[llvm] [AMDGPU] Do not use original PHIs in coercion chains (PR #98063)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 01:40:36 PDT 2024


================
@@ -365,13 +365,26 @@ bool LiveRegOptimizer::optimizeLiveType(
       else
         MissingIncVal = true;
     }
-    Instruction *DeadInst = Phi;
+
     if (MissingIncVal) {
-      DeadInst = cast<Instruction>(ValMap[Phi]);
-      // Do not use the dead phi
-      ValMap[Phi] = Phi;
-    }
-    DeadInsts.emplace_back(DeadInst);
+      Value *DeadVal = ValMap[Phi];
+      // The coercion chain of the PHI is broken. Delete the Phi
+      // from the ValMap and any connected / user Phis.
+      SmallVector<Value *, 4> PHIWorklist;
+      PHIWorklist.push_back(DeadVal);
+      while (!PHIWorklist.empty()) {
+        Value *NextDeadValue = PHIWorklist.pop_back_val();
+        ValMap.erase(NextDeadValue);
+        DeadInsts.emplace_back(cast<Instruction>(NextDeadValue));
+
+        for (User *U : cast<Instruction>(NextDeadValue)->users()) {
+          assert(isa<PHINode>(U));
+          if (ValMap.contains(cast<Instruction>(U)))
----------------
arsenm wrote:

just cast<PHINode> instead of assert + less specific cast 

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


More information about the llvm-commits mailing list