<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 21, 2014 at 10:00 AM, Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>So why in some cases does it still produce the nsw/nuw flag? Just curious.</div></div></blockquote><div><br></div><div>Let's say you had:</div><div>%mul = mul nsw i32 %V, 2</div><div><br></div><div>This can safely be transformed into:</div><div>%mul = shl nsw i32 %V, 1<br></div><div><br></div><div>However, let's take the example:</div><div><div>%mul = mul nsw i32 %V, -2147483648</div>







</div><div><br></div><div>We cannot transform this into:</div><div>%mul = shl nsw i32 %V, 31</div><div><br></div><div>If we did this, then we would have created a poison value where non previously existed.</div><div>This is because when %V is 1, 1 * -2147483648 is just -2147483648 but 1 << 31 violates NSW.</div><div><br></div><div>Instead, we end up with:</div><div>%mul = shl i32 %V, 31<br></div><div><br></div><div>I don't think it's correct to see 'shl nsw' as an arithmetic left-shift and 'shl nuw' as a logical shift.</div><div>Where would that leave 'shl nsw nuw' ?</div><div><br></div><div>Finally, nsw and nuw flags are permitted to be ignored or otherwise dropped when optimizing or performing analysis.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>We are going with intrinsics, but I'm still curious. Thanks.</div></div><div class=""><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 21, 2014 at 12:54 PM, David Chisnall <span dir="ltr"><<a href="mailto:David.Chisnall@cl.cam.ac.uk" target="_blank">David.Chisnall@cl.cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>On 21 Nov 2014, at 17:39, Ryan Taylor <<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>> wrote:<br>
<br>
> I don't care if clang only produces shl, I'm more curious how to get the signed info to the backend for shl when it's not producing a nsw/nuw flag? I'm currently not sure how this would be done, is there another arch that manages this somehow?<br>
<br>
</span>I think the point is that the only difference between the two is the overflow flag, which is not something that C exposes, and LLVM IR tends to be driven by the needs of the front ends.<br>
<br>
If you wanted an IR instruction that represented a left shift that set a flag, then you'd need something that returned both the result and the overflow flag (look at the existing overflow checked addition intrinsics for inspiration).  This sort of thing tends only to be added when someone needs it.  If the first someone to need it is you, then... patches welcome.  I think that you'd probably want to implement it as a shift-with-overflow intrinsic rather than a variation on the shl instruction and you'd probably need to provide some expansion for it for processors that don't have a direct mapping.<br>
<span><font color="#888888"><br>
David<br>
<br>
</font></span></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>