[llvm] [Scalar] Avoid repeated hash lookups (NFC) (PR #132330)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 20 20:56:54 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/132330.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+11-9)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 364fe5a9fad11..ef425e0318ea9 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1182,11 +1182,12 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
for (unsigned i = 0; i < NumPHIValues; i++) {
Value *InVal = PN->getIncomingValue(i);
BasicBlock *InBB = PN->getIncomingBlock(i);
- if (!BlockToValue.count(InBB))
- BlockToValue[InBB] = getBaseForInput(InVal, InBB->getTerminator());
+ auto [It, Inserted] = BlockToValue.try_emplace(InBB);
+ if (Inserted)
+ It->second = getBaseForInput(InVal, InBB->getTerminator());
else {
#ifndef NDEBUG
- Value *OldBase = BlockToValue[InBB];
+ Value *OldBase = It->second;
Value *Base = getBaseForInput(InVal, nullptr);
// We can't use `stripPointerCasts` instead of this function because
@@ -1206,7 +1207,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
"findBaseOrBDV should be pure!");
#endif
}
- Value *Base = BlockToValue[InBB];
+ Value *Base = It->second;
BasePHI->setIncomingValue(i, Base);
}
} else if (SelectInst *BaseSI =
@@ -1545,9 +1546,10 @@ static void CreateGCRelocates(ArrayRef<Value *> LiveVariables,
Value *LiveIdx = Builder.getInt32(i);
Type *Ty = LiveVariables[i]->getType();
- if (!TypeToDeclMap.count(Ty))
- TypeToDeclMap[Ty] = getGCRelocateDecl(Ty);
- Function *GCRelocateDecl = TypeToDeclMap[Ty];
+ auto [It, Inserted] = TypeToDeclMap.try_emplace(Ty);
+ if (Inserted)
+ It->second = getGCRelocateDecl(Ty);
+ Function *GCRelocateDecl = It->second;
// only specify a debug name if we can give a useful one
CallInst *Reloc = Builder.CreateCall(
@@ -2378,9 +2380,9 @@ findRematerializationCandidates(PointerToBaseTy PointerToBase,
// Handle the scenario where the RootOfChain is not equal to the
// Base Value, but they are essentially the same phi values.
- if (RootOfChain != PointerToBase[Derived]) {
+ if (Value *BaseVal = PointerToBase[Derived]; RootOfChain != BaseVal) {
PHINode *OrigRootPhi = dyn_cast<PHINode>(RootOfChain);
- PHINode *AlternateRootPhi = dyn_cast<PHINode>(PointerToBase[Derived]);
+ PHINode *AlternateRootPhi = dyn_cast<PHINode>(BaseVal);
if (!OrigRootPhi || !AlternateRootPhi)
continue;
// PHI nodes that have the same incoming values, and belonging to the same
``````````
</details>
https://github.com/llvm/llvm-project/pull/132330
More information about the llvm-commits
mailing list