[llvm-dev] Unsigned int displaying as negative

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 16 11:23:52 PST 2017


On 16 February 2017 at 10:15, Ryan Taylor <ryta1203 at gmail.com> wrote:
> The issue is saturation is treated differently for signed than it is for
> unsigned.

Saturation is overflow, which means it's not allowed in C for unsigned
integer types (they have to wrap) and irrelevant for signed (as soon
as you overflow you're in undefined behaviour territory). LLVM IR
follows C and doesn't represent saturation -- in particular
optimization passes before CodeGen will be very happy to change your
results if you're relying on it, with or without "nsw".

ARM has some saturating instructions too. The only way to access them
is via intrinsics, both at the C level and LLVM IR.

Tim.


More information about the llvm-dev mailing list