[llvm] LangRef: storing poison in memory is UB (PR #141339)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon May 26 13:05:27 PDT 2025


nikic wrote:

> Load widening can be solved by using vector loads or struct loads (if the new size is not a multiple of the old one).

Neither of those can be used for load widening in any practical sense. Struct loads are non-canonical and will very likely be removed entirely in the future. Vector operations come with a *strong* hint to actually lower them to vector instructions, which is undesirable for load widening use cases.

> There are implications about making stores UB, such as making movement of stores and function calls even harder.

I don't think that this materially restricts the kind of store speculation we can perform currently. The speculated stores are spurious, i.e. they will store back a loaded loaded value, which can't be poison. (The only problematic interaction here is with metadata.)

> I don't think it's that hard to fix. Widening happens just in a few places. (like lowering on memory intrinsics such as memcpy/memcmp) and some codegen prepare.

The most important case is SROA, and I don't think it's easy to fix. The byte type is part of what is needed, but it's not sufficient in itself (for good optimization quality).

-----

Anyway, I see this as just documenting the status quo. It seems like we will be moving away from this *eventually*, so it probably doesn't make sense to try to make us strictly conforming to this model, but it's an important constraint to be aware of as things are right now.

I think Ralf's phrasing here makes it clear that this is not intended as the permanent state of things.

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


More information about the llvm-commits mailing list