<div dir="ltr"><div>I have a buildbot breakage that started nearby this commit. This looks like the most likely culprit. Bug report here:</div><div><br></div><a href="https://bugs.llvm.org/show_bug.cgi?id=34349">https://bugs.llvm.org/show_bug.cgi?id=34349</a><br><div><br></div><div>- Andrew</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 25, 2017 at 11:39 AM, Craig Topper 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: ctopper<br>
Date: Fri Aug 25 11:39:40 2017<br>
New Revision: 311789<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=311789&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=311789&view=rev</a><br>
Log:<br>
[InstCombine] Don't fall back to only calling computeKnownBits if the upper bit of Add/Sub is demanded.<br>
<br>
Just create an all 1s demanded mask and continue recursing like normal. The recursive calls should be able to handle an all 1s mask and do the right thing.<br>
<br>
The only time we should care about knowing whether the upper bit was demanded is when we need to know if we should clear the NSW/NUW flags.<br>
<br>
Now that we have a consistent path through the code for all cases, use KnownBits::computeForAddSub to compute the known bits at the end since we already have the LHS and RHS.<br>
<br>
My larger goal here is to move the code that turns add into xor if only 1 bit is demanded and no bits below it are non-zero from InstCombiner::OptAndOp to here. This will allow it to be more general instead of just looking for 'add' and 'and' with constant RHS.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D36486" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D36486</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp?rev=311789&r1=311788&r2=311789&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp?rev=311789&r1=311788&r2=<wbr>311789&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp Fri Aug 25 11:39:40 2017<br>
@@ -396,38 +396,39 @@ Value *InstCombiner::<wbr>SimplifyDemandedUse<br>
     /// If the high-bits of an ADD/SUB are not demanded, then we do not care<br>
     /// about the high bits of the operands.<br>
     unsigned NLZ = DemandedMask.<wbr>countLeadingZeros();<br>
-    if (NLZ > 0) {<br>
-      // Right fill the mask of bits for this ADD/SUB to demand the most<br>
-      // significant bit and all those below it.<br>
-      APInt DemandedFromOps(APInt::<wbr>getLowBitsSet(BitWidth, BitWidth-NLZ));<br>
-      if (ShrinkDemandedConstant(I, 0, DemandedFromOps) ||<br>
-          SimplifyDemandedBits(I, 0, DemandedFromOps, LHSKnown, Depth + 1) ||<br>
-          ShrinkDemandedConstant(I, 1, DemandedFromOps) ||<br>
-          SimplifyDemandedBits(I, 1, DemandedFromOps, RHSKnown, Depth + 1)) {<br>
+    // Right fill the mask of bits for this ADD/SUB to demand the most<br>
+    // significant bit and all those below it.<br>
+    APInt DemandedFromOps(APInt::<wbr>getLowBitsSet(BitWidth, BitWidth-NLZ));<br>
+    if (ShrinkDemandedConstant(I, 0, DemandedFromOps) ||<br>
+        SimplifyDemandedBits(I, 0, DemandedFromOps, LHSKnown, Depth + 1) ||<br>
+        ShrinkDemandedConstant(I, 1, DemandedFromOps) ||<br>
+        SimplifyDemandedBits(I, 1, DemandedFromOps, RHSKnown, Depth + 1)) {<br>
+      if (NLZ > 0) {<br>
         // Disable the nsw and nuw flags here: We can no longer guarantee that<br>
         // we won't wrap after simplification. Removing the nsw/nuw flags is<br>
         // legal here because the top bit is not demanded.<br>
         BinaryOperator &BinOP = *cast<BinaryOperator>(I);<br>
         BinOP.setHasNoSignedWrap(<wbr>false);<br>
         BinOP.setHasNoUnsignedWrap(<wbr>false);<br>
-        return I;<br>
       }<br>
-<br>
-      // If we are known to be adding/subtracting zeros to every bit below<br>
-      // the highest demanded bit, we just return the other side.<br>
-      if (DemandedFromOps.isSubsetOf(<wbr>RHSKnown.Zero))<br>
-        return I->getOperand(0);<br>
-      // We can't do this with the LHS for subtraction, unless we are only<br>
-      // demanding the LSB.<br>
-      if ((I->getOpcode() == Instruction::Add ||<br>
-           DemandedFromOps.isOneValue()) &&<br>
-          DemandedFromOps.isSubsetOf(<wbr>LHSKnown.Zero))<br>
-        return I->getOperand(1);<br>
+      return I;<br>
     }<br>
<br>
-    // Otherwise just hand the add/sub off to computeKnownBits to fill in<br>
-    // the known zeros and ones.<br>
-    computeKnownBits(V, Known, Depth, CxtI);<br>
+    // If we are known to be adding/subtracting zeros to every bit below<br>
+    // the highest demanded bit, we just return the other side.<br>
+    if (DemandedFromOps.isSubsetOf(<wbr>RHSKnown.Zero))<br>
+      return I->getOperand(0);<br>
+    // We can't do this with the LHS for subtraction, unless we are only<br>
+    // demanding the LSB.<br>
+    if ((I->getOpcode() == Instruction::Add ||<br>
+         DemandedFromOps.isOneValue()) &&<br>
+        DemandedFromOps.isSubsetOf(<wbr>LHSKnown.Zero))<br>
+      return I->getOperand(1);<br>
+<br>
+    // Otherwise just compute the known bits of the result.<br>
+    bool NSW = cast<<wbr>OverflowingBinaryOperator>(I)-<wbr>>hasNoUnsignedWrap();<br>
+    Known = KnownBits::computeForAddSub(I-<wbr>>getOpcode() == Instruction::Add,<br>
+                                        NSW, LHSKnown, RHSKnown);<br>
     break;<br>
   }<br>
   case Instruction::Shl: {<br>
<br>
<br>
______________________________<wbr>_________________<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/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>