[llvm] using UNDEF SDNode instead of Constant SDNode when extend the UNDEF SDNode (PR #122741)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 16 10:36:47 PST 2025


topperc wrote:

> > I think we would be able to do this for poison, but not undef. Unfortunately SelectionDAG turns poison into undef.
> 
> The IR documentation does not appear to support this. It says
> 
> > It is correct to replace a poison value with an [undef value](https://llvm.org/docs/LangRef.html#undefvalues) or any value of the type.
> 
> and
> 
> > This means that immediate undefined behavior occurs if a poison value is used as an instruction operand that has any values that trigger undefined behavior.
> 
> Any replacement of poison of the narrower type with a value (or `undef`) of the narrower type will still leave us with the same situation, and neither the call (which does not have `noundef` on the parameter of interest) nor the `sext`/`zext` conversions have immediate undefined behaviour tied to the `poison` argument of interest.
> 
> I think the direction to take here is to see if the middle-end can change the function parameter to be `noext`.

My understanding is that (zext/sext undef) needs to produce a value where all the extended bits are 0 for zext or match the original sign bit for sext. According to InstCombine, (sext/zext poison) can constant fold to poison in the larger type. If SelectionDAG preserved the difference between poison and undef, it could also constant fold to poison.

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


More information about the llvm-commits mailing list