<div dir="ltr">On Sat, Jul 13, 2013 at 12:03 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">David Majnemer wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Attached is a patch to strengthen isKnownToBeAPowerOfTwo's analysis on<br>
add instructions.<br>
<br>
It calls into ComputeMaskedBits to figure out which bits are set on both<br>
add operands and determines if the value is a power-of-two-or-zero or not.<br>
</blockquote>
<br></div></div>
+  // adding a power-of-two or zero to the same power-of-two or zero yields<br>
+  // either the original power-of-two, a larger power-of-two or zero.<br>
<br>
Sentences start with capital letters.<br></blockquote><div><br></div><div style>Done.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-    if (OverflowingBinaryOperator *VOBO = cast<<u></u>OverflowingBinaryOperator>(V))<br>
+    OverflowingBinaryOperator *VOBO = cast<<u></u>OverflowingBinaryOperator>(V);<br>
<br>
Thank you!<br>
<br>
<br>
So, you've replaced logic that only worked on 'and' operations to use ComputeMaskedBits instead. I'm not entirely convinced the new logic catches everything the old logic did. ComputeMaskedBits needs to know exactly which n-th bit is set, isKnownToBeAPowerOfTwo does not. That's why we have this function at all.<br>

<br>
The previous code should fire on:<br>
<br>
define void @test(i32 %x, i32 %y) {<br>
  %A = shl i32 1, %x<br>
  %B = shl i32 1, %y<br>
  %C = and i32 %A, %B<br>
  %D = add i32 %C, %A<br>
  ; check %D here (isZero=true)<br>
  [...]<br>
<br>
and I don't think the new code will.</blockquote><div><br></div><div style>Correct, I added the old logic back with a test so that it won't get removed by accident again.</div><div style><br></div><div style>Thanks for taking a look!</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888"><br>
<br>
Nick<br>
</font></span></blockquote></div><br></div></div>