<div dir="ltr">This should have been squashed with r<span style="font-size:12.8000001907349px">248074, the test for this change is there.</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 18, 2015 at 5:48 PM, David Majnemer via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: majnemer<br>
Date: Fri Sep 18 19:48:26 2015<br>
New Revision: 248073<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=248073&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=248073&view=rev</a><br>
Log:<br>
[InstCombine] FoldICmpCstShrCst didn't handle icmps of -1 in the ashr case correctly<br>
<br>
Modified:<br>
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=248073&r1=248072&r2=248073&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=248073&r1=248072&r2=248073&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Fri Sep 18 19:48:26 2015<br>
@@ -1074,18 +1074,22 @@ Instruction *InstCombiner::FoldICmpCstSh<br>
   if (AP1 == AP2)<br>
     return getICmp(I.ICMP_EQ, A, ConstantInt::getNullValue(A->getType()));<br>
<br>
-  // Get the distance between the highest bit that's set.<br>
   int Shift;<br>
-  // Both the constants are negative, take their positive to calculate log.<br>
   if (IsAShr && AP1.isNegative())<br>
-    // Get the ones' complement of AP2 and AP1 when computing the distance.<br>
-    Shift = (~AP2).logBase2() - (~AP1).logBase2();<br>
+    Shift = AP1.countLeadingOnes() - AP2.countLeadingOnes();<br>
   else<br>
-    Shift = AP2.logBase2() - AP1.logBase2();<br>
+    Shift = AP1.countLeadingZeros() - AP2.countLeadingZeros();<br>
<br>
   if (Shift > 0) {<br>
-    if (IsAShr ? AP1 == AP2.ashr(Shift) : AP1 == AP2.lshr(Shift))<br>
+    if (IsAShr && AP1 == AP2.ashr(Shift)) {<br>
+      // There are multiple solutions if we are comparing against -1 and the LHS<br>
+      // of the ashr is not a power of two..<br>
+      if (AP1.isAllOnesValue() && !AP2.isPowerOf2())<br>
+        return getICmp(I.ICMP_UGE, A, ConstantInt::get(A->getType(), Shift));<br>
       return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift));<br>
+    } else if (AP1 == AP2.lshr(Shift)) {<br>
+      return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift));<br>
+    }<br>
   }<br>
   // Shifting const2 will never be equal to const1.<br>
   return getConstant(false);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>