[llvm] [NFCI] Replace getAllocatedType with tracked value type in RewriteStatepointsForGC (PR #177440)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 22 11:16:07 PST 2026
https://github.com/vtjnash updated https://github.com/llvm/llvm-project/pull/177440
>From 03eea4a5a9140f49dc681f77d9b970919a5dd94c Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash+github at gmail.com>
Date: Wed, 21 Jan 2026 19:00:04 +0000
Subject: [PATCH] [NFCI] Replace getAllocatedType() with tracked value type in
RewriteStatepointsForGC
The allocas in RewriteStatepointsForGC are created with
LiveValue->getType(), so we can use Def->getType() (which equals the
alloca's type) instead of querying getAllocatedType().
Changes:
- Load instructions now use Def->getType() directly
- The ToClobber vector now stores (Type*, AllocaInst*) pairs to track
the original value's type for creating null constants
Co-Authored-By: Claude Opus 4.5 <noreply at anthropic.com>
---
.../Scalar/RewriteStatepointsForGC.cpp | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 74448d872aad2..230df9f971a71 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -2094,7 +2094,7 @@ static void relocationViaAlloca(
// slightly easier to debug SEGVs. Note that on large IR files with
// lots of gc.statepoints this is extremely costly both memory and time
// wise.
- SmallVector<AllocaInst *, 64> ToClobber;
+ SmallVector<std::pair<Type *, AllocaInst *>, 64> ToClobber;
for (auto Pair : AllocaMap) {
Value *Def = Pair.first;
AllocaInst *Alloca = Pair.second;
@@ -2103,17 +2103,17 @@ static void relocationViaAlloca(
if (VisitedLiveValues.count(Def)) {
continue;
}
- ToClobber.push_back(Alloca);
+ // Track Def's type since the alloca was created with that type.
+ ToClobber.push_back({Def->getType(), Alloca});
}
auto InsertClobbersAt = [&](BasicBlock::iterator IP) {
- for (auto *AI : ToClobber) {
- auto AT = AI->getAllocatedType();
+ for (auto &[Ty, AI] : ToClobber) {
Constant *CPN;
- if (AT->isVectorTy())
- CPN = ConstantAggregateZero::get(AT);
+ if (Ty->isVectorTy())
+ CPN = ConstantAggregateZero::get(Ty);
else
- CPN = ConstantPointerNull::get(cast<PointerType>(AT));
+ CPN = ConstantPointerNull::get(cast<PointerType>(Ty));
new StoreInst(CPN, AI, IP);
}
};
@@ -2161,15 +2161,17 @@ static void relocationViaAlloca(
PHINode *Phi = cast<PHINode>(Use);
for (unsigned i = 0; i < Phi->getNumIncomingValues(); i++) {
if (Def == Phi->getIncomingValue(i)) {
+ // Use Def's type since the alloca was created with that type.
LoadInst *Load = new LoadInst(
- Alloca->getAllocatedType(), Alloca, "",
+ Def->getType(), Alloca, "",
Phi->getIncomingBlock(i)->getTerminator()->getIterator());
Phi->setIncomingValue(i, Load);
}
}
} else {
- LoadInst *Load = new LoadInst(Alloca->getAllocatedType(), Alloca, "",
- Use->getIterator());
+ // Use Def's type since the alloca was created with that type.
+ LoadInst *Load =
+ new LoadInst(Def->getType(), Alloca, "", Use->getIterator());
Use->replaceUsesOfWith(Def, Load);
}
}
More information about the llvm-commits
mailing list