Skip to content

Commit f67b154

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339309 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0cb6e74 commit f67b154

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/Transforms/IPO/ConstantMerge.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,12 @@ static bool mergeConstants(Module &M) {
174174
Constant *Init = GV->getInitializer();
175175

176176
// Check to see if the initializer is already known.
177-
GlobalVariable *Slot = CMap[Init];
177+
auto Found = CMap.find(Init);
178+
if (Found == CMap.end())
179+
continue;
178180

179-
if (!Slot || Slot == GV)
181+
GlobalVariable *Slot = Found->second;
182+
if (Slot == GV)
180183
continue;
181184

182185
if (!Slot->hasGlobalUnnamedAddr() && !GV->hasGlobalUnnamedAddr())

0 commit comments

Comments
 (0)