[LLVMdev] Does lli know how to interpret arithmetic overflow intrinsics?

Duncan Sands baldrick at free.fr
Thu May 5 02:12:12 PDT 2011


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.

>
>
> - sanjiv
>
> On Thu, May 5, 2011 at 11:18 AM, Sanjiv <llvmdev at gmail.com
> <mailto:llvmdev at gmail.com>> wrote:
>
>     Do we have a .ll test cases for arithmetic overflow intrinsics that lli can
>     execute and report any overflow occured?
>
>     - sanjiv
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list