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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 13:50:26 PDT 2026


================
@@ -0,0 +1,192 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes=sroa -S | FileCheck %s
+
+; SROA should use lifetime intrinsics to avoid creating recurrent PHI nodes
+; when promoting struct allocas.
+;
+; The alloca is reused across loop iterations. Without lifetime markers, SROA
+; must conservatively assume the i32 field retains its value on the skip path,
+; so it inserts a back-edge PHI at the loop header carrying the previous
+; iteration's value.
+;
+; With lifetime.start at the top of the loop, the alloca's content is
+; logically undefined at that point each iteration. SROA should propagate this
+; onto each slice alloca: PromoteMemToReg can then treat lifetime.start as an
+; implicit "store undef", breaking the back-edge dependence and eliminating
+; the recurrent PHI.
+;
+; PromoteMemToReg treats lifetime markers as implicit "store undef", breaking
+; back-edge dependences and eliminating recurrent PHIs in @with_lifetime and
+; @with_lifetime_end.
+
+%struct.S = type { i8, i32, i8 }
+
+declare void @use(i32)
+declare void @llvm.lifetime.start.p0(ptr captures(none))
+declare void @llvm.lifetime.end.p0(ptr captures(none))
----------------
nikic wrote:

Don't declare intrinsics.

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


More information about the llvm-commits mailing list