[llvm] [NewGVN] Patch replacement instruction even for removed instructions (PR #67426)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 03:09:30 PDT 2023


================
@@ -4030,9 +4030,19 @@ bool NewGVN::eliminateInstructions(Function &F) {
             // because stores are put in terms of the stored value, we skip
             // stored values here. If the stored value is really dead, it will
             // still be marked for deletion when we process it in its own class.
-            if (!EliminationStack.empty() && Def != EliminationStack.back() &&
-                isa<Instruction>(Def) && !FromStore)
-              markInstructionForDeletion(cast<Instruction>(Def));
+            auto *DefI = dyn_cast<Instruction>(Def);
+            if (!EliminationStack.empty() && DefI && !FromStore) {
+              Value *DominatingLeader = EliminationStack.back();
+              if (DominatingLeader != Def) {
+                // Even if the instruction is removed, we still need to update
+                // flags/metadata due to downstreams users of the leader.
+                auto *II = dyn_cast<IntrinsicInst>(DefI);
+                if (!II || II->getIntrinsicID() != Intrinsic::ssa_copy)
----------------
fhahn wrote:

nit: using `match(DefI, m_Intrinsic<Instrinsic::ssa_copy>())` may be slightly shorter

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


More information about the llvm-commits mailing list