Revert "[BypassSlowDivision] Improve our handling of divisions by constants"
This reverts commit r314253. It causes a miscompile on P100 in an internal
benchmark. Reverting while I investigate.
llvm-svn: 314482
diff --git a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
index 4aed897..d6c31f2 100644
--- a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
+++ b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
@@ -339,6 +339,11 @@
Value *Dividend = SlowDivOrRem->getOperand(0);
Value *Divisor = SlowDivOrRem->getOperand(1);
+ if (isa<ConstantInt>(Divisor)) {
+ // Keep division by a constant for DAGCombiner.
+ return None;
+ }
+
VisitedSetTy SetL;
ValueRange DividendRange = getValueRange(Dividend, SetL);
if (DividendRange == VALRNG_LIKELY_LONG)
@@ -354,9 +359,7 @@
if (DividendShort && DivisorShort) {
// If both operands are known to be short then just replace the long
- // division with a short one in-place. Since we're not introducing control
- // flow in this case, narrowing the division is always a win, even if the
- // divisor is a constant (and will later get replaced by a multiplication).
+ // division with a short one in-place.
IRBuilder<> Builder(SlowDivOrRem);
Value *TruncDividend = Builder.CreateTrunc(Dividend, BypassType);
@@ -366,16 +369,7 @@
Value *ExtDiv = Builder.CreateZExt(TruncDiv, getSlowType());
Value *ExtRem = Builder.CreateZExt(TruncRem, getSlowType());
return QuotRemPair(ExtDiv, ExtRem);
- }
-
- if (isa<ConstantInt>(Divisor)) {
- // If the divisor is not a constant, DAGCombiner will convert it to a
- // multiplication by a magic constant. It isn't clear if it is worth
- // introducing control flow to get a narrower multiply.
- return None;
- }
-
- if (DividendShort && !isSignedOp()) {
+ } else if (DividendShort && !isSignedOp()) {
// If the division is unsigned and Dividend is known to be short, then
// either
// 1) Divisor is less or equal to Dividend, and the result can be computed