[LLVMdev] The nsw story

Eli Friedman eli.friedman at gmail.com
Tue Dec 6 11:55:52 PST 2011

On Tue, Dec 6, 2011 at 9:18 AM, David A. Greene <greened at obbligato.org> wrote:
> Chris Lattner <clattner at apple.com> writes:
>>> No; sext i32 undef to i64 returns an extraordinary thing. It's a
>>> 64-bit value where the low 32 bits are undef, and the high
>>> 32 bits are sign extension from whatever bit 31 happened to be.
>> More precisely, the high 33 bits are known to be the same.
> I think that's a very risky assumption.  The name "undef" does not
> convey that at all.
>>> operands and opcodes. It's quite magical.
>> It's actually not that magical.  It's also essential that we have this
>> behavior, otherwise normal bitfield code has "undefined" behavior and
>> is misoptimized.  This is why the result of "undef & 1" is known to
>> have high bits zero.
> Well sure, because we know (x & 1) has the high bits set to zero for any
> value of x.  In the sext case, we know nothing about the high bits
> because we don't know what bit 32 was/is.
> Yes, we know the high bits are the same but it's surprising to me that
> this would be represented as "undef."

We don't represent that as undef in the IR; constant folding will fold
"sext i32 undef to i64" to zero, not undef.


More information about the llvm-dev mailing list