[LLVMdev] Question Regarding Sign-Overflow

Nuno Lopes nunoplopes at sapo.pt
Wed Jun 25 14:00:26 PDT 2014


You're right; there's a bug.

I proved, however, the correctness of two cases:
 1) X - (0 -nuw A) -> X +nuw nsw A
 2) X -nsw (0 -nsw A) -> X +nsw A

Not sure if the complexity of implementing this is worth the trouble, 
though.

Nuno

----- Original Message ----- 
From: "Jingyue Wu" <jingyue at google.com>
Sent: Wednesday, June 25, 2014 5:48 AM
Subject: [LLVMdev] Question Regarding Sign-Overflow


> Hi,
>
> I have doubts on the following transformation in InstCombineAddSub.cpp. Is
> it always safe to preserve NSW/NUW in this case?
>
>   // If this is a 'B = x-(-A)', change to B = x+A.  This preserves 
> NSW/NUW.
>   if (Value *V = dyn_castNegVal(Op1)) {
>     BinaryOperator *Res = BinaryOperator::CreateAdd(Op0, V);
>     Res->setHasNoSignedWrap(I.hasNoSignedWrap());
>     Res->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
>     return Res;
>   }
>
> Suppose A = x = (i4 -8) (the minimum signed integer of i4). The first
> minus in x - (-A) does not sign-overflow, but x + A sign-overflows.
>
> Thanks,
> Jingyue 




More information about the llvm-dev mailing list