[clang] [llvm] [PromoteMemToReg] Insert store undef when removing lifetime markers (PR #191909)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 13 22:46:37 PDT 2026


================
@@ -546,9 +546,32 @@ static void removeIntrinsicUsers(AllocaInst *AI) {
           Inst->dropDroppableUse(UU);
           continue;
         }
+
+        // Replace lifetime markers with a store of undef so that mem2reg sees
+        // the alloca as having an undefined value at that point. This allows
+        // it to break unnecessary back-edge PHI nodes created when the alloca
+        // is reused across loop iterations.
+        if (auto *II = dyn_cast<IntrinsicInst>(Inst))
----------------
efriedma-quic wrote:

It shouldn't be possible for a lifetime intrinsic to have an operand that isn't the alloca itself (the verifier checks this now).

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


More information about the cfe-commits mailing list