[LLVMdev] The nsw story
me22
me22.ca at gmail.com
Mon Dec 5 17:50:48 PST 2011
On Thu, Dec 1, 2011 at 09:23, Dan Gohman <gohman at apple.com> wrote:
>
> int a = INT_MAX, b = 1;
> long c = (long)(a + b);
>
> What is the value of c, on an LP64 target?
>
> If a and b are promoted to 64-bit, c is 0x0000000080000000.
>
> In a world where signed add overflow returns undef, c could be any of
> 0x0000000000000000
> ...
> 0xffffffffffffffff
> however it can't ever be 0x0000000080000000, because there's no 32-bit value
> the undef could take which sign-extends into that 64-bit value.
>
But since the add nsw returns undef, then isn't c "sext i32 undef to
i64", and thus also undef?
I read it like this example from LangRef:
%B = undef
%C = xor %B, %B
Safe:
%C = undef
%C is undef, so can be later (in a bitwise or, for example) assumed to
be -1, even though there's no possible choice of value for %B such
that %B xor %B gives -1.
Confused,
~ Scott
More information about the llvm-dev
mailing list