[PATCH] D50476: ConstantMerge: don't insert when find should be used

JF Bastien via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 8 14:06:52 PDT 2018


jfb created this revision.
Herald added subscribers: llvm-commits, dexonsmith.

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).


Repository:
  rL LLVM

https://reviews.llvm.org/D50476

Files:
  lib/Transforms/IPO/ConstantMerge.cpp


Index: lib/Transforms/IPO/ConstantMerge.cpp
===================================================================
--- lib/Transforms/IPO/ConstantMerge.cpp
+++ lib/Transforms/IPO/ConstantMerge.cpp
@@ -174,9 +174,12 @@
       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())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50476.159791.patch
Type: text/x-patch
Size: 649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180808/8f16f284/attachment.bin>


More information about the llvm-commits mailing list