[llvm] [mlir] [polly] [IR] Only allow lifetime.start/end on allocas (PR #149310)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 26 10:37:49 PDT 2025


efriedma-quic wrote:

I don't know if anyone is currently planning to implement anything, but I have some ideas.

One approach is to introduce an intrinsic `void llvm,write.undef.i64(ptr, i64)` which is just a write of N bytes of undef to the memory in question.  Transforms would model it like memset, except it doesn't actually lower to any code.  This would allow dead store elimination, and not much else.  Not very powerful, but easy to implement, and maybe useful in some cases.  I think this is basically equivalent to what lifetime.start and lifetime.end did for non-alloca memory.

Another option is a pair of intrinsics: `ptr llvm.allocate.provenance.i64(ptr, i64)`, and `ptr llvm.free.provenance.i64(ptr, i64)`.  The first intrinsic takes a pointer and a size, and returns a pointer with the same pointer value, but unique provenance.  The second takes the pointer returned by the first intrinsic, and the size passed to the first intrinsic, and returns the original pointer.  Between the allocate and free, all accesses to the memory must be through the pointer returned by "allocate".  This is effectively malloc and free, but you bring your own memory.  Maybe a little tricky to get alias analysis to handle this the way you want, and it's easy for code generators to generate code that has undefined behavior.   But very powerful for optimizations because the returned pointer is inherently "noalias" with any other pointer.

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


More information about the llvm-commits mailing list