[LLVMdev] No Signed Wrap

me22 me22.ca at gmail.com
Sun Jun 19 21:05:45 PDT 2011


On Sun, Jun 19, 2011 at 08:02, Frits van Bommel <fvbommel at gmail.com> wrote:
> On 19 June 2011 15:46, Duncan Sands <baldrick at free.fr> wrote:
>>
>> The transform you mentioned would convert this into:
>>
>>   %add2 = add i8 %x, -126
>>
>> Notice how when %x = -20 there is now a signed wrap in the addition.
>
> So there are (at least) two conditions:
> a) Both adds must be NSW.
> b) Adding their constant operands must itself be NSW.
>
> Any others? Because (b) should be pretty easy to check for, at least
> if both constant operands are ConstantInts like in these examples.
>

In this case it would be safe to turn that into

    %add2 = sub nuw i8 %x, 126

since the initial nsw constraints mean that %x must be in [-128, -3],
aka [128, 253].

Would a change like that always be feasible for folds with condition
(b)?  It sounds plausible...




More information about the llvm-dev mailing list