[InstCombine] Only propagate known leading zeros from udiv input to output.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 10 May 2018 11:45:18 +0000 (11:45 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 10 May 2018 11:45:18 +0000 (11:45 +0000)
Put in a conservatively correct estimate for now. Avoids miscompiling
clang in FDO mode. This is really tricky to trigger in reality as
basically all interesting cases will be folded away by computeKnownBits
earlier, I was unable to find a reasonably small test case.

llvm-svn: 331975

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

index abd3e39..a475a27 100644 (file)
@@ -554,10 +554,15 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
         break;
 
       // FIXME: Take the demanded mask of the result into account.
+      unsigned RHSTrailingZeros = SA->countTrailingZeros();
       APInt DemandedMaskIn =
-          APInt::getHighBitsSet(BitWidth, BitWidth - SA->countTrailingZeros());
-      if (SimplifyDemandedBits(I, 0, DemandedMaskIn, Known, Depth + 1))
+          APInt::getHighBitsSet(BitWidth, BitWidth - RHSTrailingZeros);
+      if (SimplifyDemandedBits(I, 0, DemandedMaskIn, LHSKnown, Depth + 1))
         return I;
+
+      // Propagate zero bits from the input.
+      Known.Zero.setHighBits(std::min(
+          BitWidth, LHSKnown.Zero.countLeadingOnes() + RHSTrailingZeros));
     }
     break;
   }