diff options
| author | JF Bastien <jfbastien@apple.com> | 2018-08-09 04:17:48 +0000 |
|---|---|---|
| committer | JF Bastien <jfbastien@apple.com> | 2018-08-09 04:17:48 +0000 |
| commit | 3f270336e1c4e69ead7d7f78e3d2f9c1d859f40d (patch) | |
| tree | 99e32444a672652e19c1578fec676d62f4b651cd | |
| parent | 22b20a09a08baba62f69f19e65c79b59f15cb0e0 (diff) | |
| download | bcm5719-llvm-3f270336e1c4e69ead7d7f78e3d2f9c1d859f40d.tar.gz bcm5719-llvm-3f270336e1c4e69ead7d7f78e3d2f9c1d859f40d.zip | |
[NFC] ConstantMerge: don't insert when find should be used
Summary: DenseMap's operator[] performs an insertion if the entry isn't found. The second phase of ConstantMerge isn't trying to insert anything: it's just looking to see if the first phased performed an insertion. Use find instead, avoiding insertion of every single global initializer in the map of constants. This has the side-effect of making all entries in CMap non-null (because only global declarations would have null initializers, and that would be a bug).
Subscribers: dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D50476
llvm-svn: 339309
| -rw-r--r-- | llvm/lib/Transforms/IPO/ConstantMerge.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp index e0b1037053f..a6cfbb26e79 100644 --- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp +++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp @@ -174,9 +174,12 @@ static bool mergeConstants(Module &M) { Constant *Init = GV->getInitializer(); // Check to see if the initializer is already known. - GlobalVariable *Slot = CMap[Init]; + auto Found = CMap.find(Init); + if (Found == CMap.end()) + continue; - if (!Slot || Slot == GV) + GlobalVariable *Slot = Found->second; + if (Slot == GV) continue; if (!Slot->hasGlobalUnnamedAddr() && !GV->hasGlobalUnnamedAddr()) |

