Does lli know how to interpret arithmetic overflow intrinsics?

Do we have a .ll test cases for arithmetic overflow intrinsics that lli can execute and report any overflow occured?

  • sanjiv

I understand that overflow behaviours can be different on different hardware. But can we write .ll implementation of these overflow intrinsics, e.g. assuming 0…255 as value range for unsigned i8 ?

  • sanjiv

Hi Sanjiv,

I understand that overflow behaviours can be different on different hardware.
But can we write .ll implementation of these overflow intrinsics, e.g. assuming
0..255 as value range for unsigned i8 ?

I'm not sure I understand what you are asking, but it is perfectly possible to
write generic versions of overflow intrinsics. For example, if %x and %y have
type iN, and you are interested in signed/unsigned overflow when adding them,
then: (1) sext/zext %x and %y to variables %X and %Y of type i(N+1) (one more
bit); (2) compute %Z = %X + %Y; (3) Check that %Z sexts/zexts its truncation to
type iN, i.e. that "%Z == sext (trunc %Z to iN) to i(N+1)" (likewise for zext).
If not, the computation overflowed. Likewise for subtraction. For
multiplication you need to double the number of bits, but otherwise it is the
same.

Ciao, Duncan.