[llvm] [LLVM][ConstantFold] Undefined values are not constant (PR #130713)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 10 21:46:42 PDT 2025


efriedma-quic wrote:

> IMO `undef/poison` can be refined to any constant value.

Agreed.

To explain to anyone else who isn't following... suppose you have `__builtin_constant_p(cond ? 0 : uninit_variable)`.  Existing optimizations want to fold `cond ? 0 : uninit_variable` to zero... but then __builtin_constant_p is returning true for a value that's supposed to be undef.  So undefined values may or may not be constant, depending on the context.

Of course, that's true with or without this patch, so I guess you could argue that this patch is an improvement anyway.  But really, we need to fix Linux code so it doesn't depend on this behavior, or we'll trip over it again later.

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


More information about the llvm-commits mailing list