[llvm] 15e6b5d - [Transforms] Avoid repeated hash lookups (NFC) (#109565)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 22 00:20:20 PDT 2024


Author: Kazu Hirata
Date: 2024-09-22T00:20:17-07:00
New Revision: 15e6b5d643618d0c477d31188f6894a31bad98d8

URL: https://github.com/llvm/llvm-project/commit/15e6b5d643618d0c477d31188f6894a31bad98d8
DIFF: https://github.com/llvm/llvm-project/commit/15e6b5d643618d0c477d31188f6894a31bad98d8.diff

LOG: [Transforms] Avoid repeated hash lookups (NFC) (#109565)

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/IROutliner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index ec72741c06e73d..20d2d46e79ebcc 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -787,10 +787,8 @@ static void findConstants(IRSimilarityCandidate &C, DenseSet<unsigned> &NotSame,
       // global value numbering.
       unsigned GVN = *C.getGVN(V);
       if (isa<Constant>(V))
-        if (NotSame.contains(GVN) && !Seen.contains(GVN)) {
+        if (NotSame.contains(GVN) && Seen.insert(GVN).second)
           Inputs.push_back(GVN);
-          Seen.insert(GVN);
-        }
     }
   }
 }
@@ -814,8 +812,9 @@ static void mapInputsToGVNs(IRSimilarityCandidate &C,
   // replacement.
   for (Value *Input : CurrentInputs) {
     assert(Input && "Have a nullptr as an input");
-    if (OutputMappings.contains(Input))
-      Input = OutputMappings.find(Input)->second;
+    auto It = OutputMappings.find(Input);
+    if (It != OutputMappings.end())
+      Input = It->second;
     assert(C.getGVN(Input) && "Could not find a numbering for the given input");
     EndInputNumbers.push_back(*C.getGVN(Input));
   }
@@ -836,8 +835,9 @@ remapExtractedInputs(const ArrayRef<Value *> ArgInputs,
   // Get the global value number for each input that will be extracted as an
   // argument by the code extractor, remapping if needed for reloaded values.
   for (Value *Input : ArgInputs) {
-    if (OutputMappings.contains(Input))
-      Input = OutputMappings.find(Input)->second;
+    auto It = OutputMappings.find(Input);
+    if (It != OutputMappings.end())
+      Input = It->second;
     RemappedArgInputs.insert(Input);
   }
 }


        


More information about the llvm-commits mailing list