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." "undef" to me means I can assume any value at all, not restricted to "all the bits are the same." -Dave
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. -Eli
Eli Friedman <eli.friedman at gmail.com> writes:>> 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.Ok, so why the fuss over sext? -Dave