[cfe-dev] Why no NSW/NUW with SHL instruction?

Ryan Taylor ryta1203 at gmail.com
Wed Nov 19 11:02:12 PST 2014


There is a difference in the backend, whether the overflow flag should be
thrown or not. We would like to produce a signed arithmetic left shift for
an int that is signed in C (ie signed int).

for example, a small test case:

signed x = -2;
unsigned y =1;

int foo() {
   x = x << y;
   return x;
}

Thank you.

On Wed, Nov 19, 2014 at 1:52 PM, Reid Kleckner <rnk at google.com> wrote:

> What is the difference between logical and arithmetic left shift on your
> target? LLVM only makes that distinction for right shift, and not for left
> shift.
>
> On Wed, Nov 19, 2014 at 10:32 AM, Ryan Taylor <ryta1203 at gmail.com> wrote:
>
>> I'm curious why there is not always a nsw/nuw flag with shl instruction?
>> For example, I have a signed int I'm shifting left (want to generate an
>> arithmetic left shift in backend for signed int shift lefts and logical for
>> unsigned, at the moment).... but shl on a signed int does not always have
>> nsw/nuw flag present, why is this?
>>
>> Thank you.
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141119/f9dd6ec5/attachment.html>


More information about the cfe-dev mailing list