<div dir="ltr"><div>On Sat, May 18, 2013 at 3:03 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra">

<div class="gmail_quote"><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>On Sat, May 18, 2013 at 1:13 PM, Duncan Sands <span dir="ltr"><<a href="mailto:duncan.sands@gmail.com" target="_blank">duncan.sands@gmail.com</a>></span> wrote:<br>

</div><div class="gmail_extra"><div class="gmail_quote"><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">Hi David,<div><br>
<br>
On 18/05/13 21:30, David Majnemer 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">
Author: majnemer<br>
Date: Sat May 18 14:30:37 2013<br>
New Revision: 182200<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=182200&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=182200&view=rev</a><br>
Log:<br>
isKnownToBeAPowerOfTwo: (X & Y) + Y is a power of 2 or zero if y is also.<br>
</blockquote>
<br></div>
if the + is nsw or nuw then the sum can't be zero.  I don't know if this is<br>
useful in practice.<br></blockquote><div><br></div></div><div>I noticed this too, I'm trying to find if I can tickle something that would make this happen.</div></div></div></div></blockquote><div><br></div><div>So, I've found a way to make this possible: set the NSW bit on the 'add' created in foldSelectICmpAnd.<br>

</div><div>Then the following:</div><div><div>  %1 = lshr i32 %x, 8</div><div>  %2 = and i32 %1, 32</div><div>  %3 = add i32 %2, 32</div><div>  %4 = xor i32 %x, -1</div><div>  %5 = and i32 %3, %4</div><div>  %6 = icmp ne i32 %5, 0</div>

<div><br></div><div>will get optimized:</div><div><div>  %and = lshr i32 %x, 8</div><div>  %0 = and i32 %and, 32</div><div>  %1 = add nsw i32 %0, 32</div><div>  %2 = and i32 %1, %x</div><div>  %tobool2 = icmp eq i32 %2, 0</div>

<div><br></div><div>My only concern is that I'm not entirely convinced that it's always safe (just mostly safe) to set the NSW bit.</div><div>Ben or Duncan (or preferably both!), does it look safe to set the NSW bit there?</div>
</div></div><div><br></div><div style>Thanks</div><div style>-- </div><div style>David Majnemer</div><div><br></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 class="gmail_extra"><div class="gmail_quote"><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">



<br>
Ciao, Duncan.<div><div><br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div></div><br></div></div>
</blockquote></div><br></div></div>