[llvm] [InstCombine] Iterative replacement in PtrReplacer (PR #137215)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 01:47:21 PDT 2025


================
@@ -365,13 +408,18 @@ 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.
+    auto GetReplacementForInValue = [&](Value *V) {
+      return WorkMap.contains(V) ? WorkMap[V] : V;
----------------
arsenm wrote:

This is still a double map lookup, you need to use a find 

https://github.com/llvm/llvm-project/pull/137215


More information about the llvm-commits mailing list