[llvm] [llvm] Support invariant.load on readonly intrinsics (PR #205916)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 26 06:04:07 PDT 2026
https://github.com/nikic commented:
So I guess the operational semantics for `!invariant.load` are something like: Mark all the memory locations loaded by the instruction as invariant. Any future writes to invariant memory are UB (or possibly any future writes that don't store back the existing value?) With the exception that the memory may be freed (though I think this requires some clarification wrt how it interacts with lifetime.end).
Generalizing this to arbitrary calls, we have some complications:
* What about memory that is written? There could be an interpretation where only memory that's read is invariant, but writes are still allowed. This is probably not a practically useful interpretation. So either writes in an operation with `!invariant.load` are UB, or it's not well-formed in the first place. The latter probably makes most sense.
* What about memory that is internal to the call? If I have an `alloca` inside the function, can I arbitrarily read and write it? I think the answer to that must be "yes".
I don't see a fundamental problem with semantics that depend on what memory is accessed during a call, but I'm also not sure it's worth the complication. cc @dtcxzyw @nofe1248 for llubi.
https://github.com/llvm/llvm-project/pull/205916
More information about the llvm-commits
mailing list