[llvm] 3e8b175 - [IR] Avoid redundant map lookup [NFC]

Jannik Silvanus via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 01:14:00 PST 2023


Author: Jannik Silvanus
Date: 2023-12-14T10:13:32+01:00
New Revision: 3e8b175eec6fef1a073fb7d0d867fbc6a7837f57

URL: https://github.com/llvm/llvm-project/commit/3e8b175eec6fef1a073fb7d0d867fbc6a7837f57
DIFF: https://github.com/llvm/llvm-project/commit/3e8b175eec6fef1a073fb7d0d867fbc6a7837f57.diff

LOG: [IR] Avoid redundant map lookup [NFC]

Use the iterator returned by MapVector::insert to update
the value in the map, instead of a second redundant map lookup.

Added: 
    

Modified: 
    llvm/lib/IR/Operator.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index 017641a8dba19d..cd982c7da102af 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -229,8 +229,8 @@ bool GEPOperator::collectOffset(
     // Insert an initial offset of 0 for V iff none exists already, then
     // increment the offset by IndexedSize.
     if (!IndexedSize.isZero()) {
-      VariableOffsets.insert({V, APInt(BitWidth, 0)});
-      VariableOffsets[V] += IndexedSize;
+      auto *It = VariableOffsets.insert({V, APInt(BitWidth, 0)}).first;
+      It->second += IndexedSize;
     }
   }
   return true;


        


More information about the llvm-commits mailing list