[llvm] [InstCombine] Iterative replacement in PtrReplacer (PR #137215)
Anshil Gandhi via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 21:51:47 PDT 2025
================
@@ -365,12 +414,20 @@ void PointerReplacer::replace(Instruction *I) {
// replacement (new value).
WorkMap[NewI] = NewI;
} else if (auto *PHI = dyn_cast<PHINode>(I)) {
- Type *NewTy = getReplacement(PHI->getIncomingValue(0))->getType();
- auto *NewPHI = PHINode::Create(NewTy, PHI->getNumIncomingValues(),
- PHI->getName(), PHI->getIterator());
+ // Create a new PHI by replacing any incoming value that is a user of the
+ // root pointer and has a replacement.
+ SmallVector<Value *, 4> IncomingValues;
+ for (unsigned int I = 0; I < PHI->getNumIncomingValues(); ++I) {
+ Value *V = getReplacement(PHI->getIncomingValue(I));
+ if (!V)
+ V = PHI->getIncomingValue(I);
----------------
gandhi56 wrote:
`@func_phi_loop` in Transforms/InstCombine/AMDGPU/ptr-replace-alloca.ll
https://github.com/llvm/llvm-project/pull/137215
More information about the llvm-commits
mailing list