[llvm] r339309 - [NFC] ConstantMerge: don't insert when find should be used

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 8 21:17:48 PDT 2018


Author: jfb
Date: Wed Aug  8 21:17:48 2018
New Revision: 339309

URL: http://llvm.org/viewvc/llvm-project?rev=339309&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp

Modified: llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp?rev=339309&r1=339308&r2=339309&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp Wed Aug  8 21:17:48 2018
@@ -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())




More information about the llvm-commits mailing list