[LLVMdev] ConstantFold 'undef xor undef'

Chris Lattner clattner at apple.com
Tue Jul 6 17:34:01 PDT 2010


On Jul 6, 2010, at 3:37 PM, Jianzhou Zhao wrote:

> Which semantics is better? I guess both are fine because if we assume
> these two def's are same, then it is 0 as
> 'ConstantFoldBinaryInstruction', while if we assume they are different
> then it is equal to undef. But the second case seems to include the
> first one. If we let undef xor undef to be undef, later we can use
> this undef as 0, but also other values w.r.t contexts. Is there any
> reason that ConstantFoldBinaryInstruction uses the first assumption?

The right answer is that undef ^ undef = undef.  Folding it to 0 is a conservatively correct approximation of undef.  This is done because (annoyingly) a lot of people write things like this:

int x;
x = x^x;

As a "clever" way of clearing out x, particularly for vectors which don't have a convenient 0 literal.  This is nonsense, but common enough to try to not completely break.

-Chris



More information about the llvm-dev mailing list