summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2016-11-16 00:44:47 +0000
committerJustin Lebar <jlebar@google.com>2016-11-16 00:44:47 +0000
commit28605735298208a848b24e95aa19a7150492db85 (patch)
tree5c07d6213b6196736d6f53ab4c64bef06b45fa3c /llvm/lib
parent583b8687eb2b3de6f57da02e3a6a2181da1d3cc4 (diff)
downloadbcm5719-llvm-28605735298208a848b24e95aa19a7150492db85.tar.gz
bcm5719-llvm-28605735298208a848b24e95aa19a7150492db85.zip
[BypassSlowDivision] Handle division by constant numerators better.
Summary: We don't do BypassSlowDivision when the denominator is a constant, but we do do it when the numerator is a constant. This patch makes two related changes to BypassSlowDivision when the numerator is a constant: * If the numerator is too large to fit into the bypass width, don't bypass slow division (because we'll never run the smaller-width code). * If we bypass slow division where the numerator is a constant, don't OR together the numerator and denominator when determining whether both operands fit within the bypass width. We need to check only the denominator. Reviewers: tra Subscribers: llvm-commits, jholewinski Differential Revision: https://reviews.llvm.org/D26699 llvm-svn: 287062
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Utils/BypassSlowDivision.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
index d74d5299db5..bc2cef26edc 100644
--- a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
+++ b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
@@ -89,6 +89,11 @@ static bool insertFastDiv(Instruction *I, IntegerType *BypassType,
return false;
}
+ // If the numerator is a constant, bail if it doesn't fit into BypassType.
+ if (ConstantInt *ConstDividend = dyn_cast<ConstantInt>(Dividend))
+ if (ConstDividend->getValue().getActiveBits() > BypassType->getBitWidth())
+ return false;
+
// Basic Block is split before divide
BasicBlock *MainBB = &*I->getParent();
BasicBlock *SuccessorBB = MainBB->splitBasicBlock(I);
@@ -150,7 +155,17 @@ static bool insertFastDiv(Instruction *I, IntegerType *BypassType,
// Combine operands into a single value with OR for value testing below
MainBB->getInstList().back().eraseFromParent();
IRBuilder<> MainBuilder(MainBB, MainBB->end());
- Value *OrV = MainBuilder.CreateOr(Dividend, Divisor);
+
+ // We should have bailed out above if the divisor is a constant, but the
+ // dividend may still be a constant. Set OrV to our non-constant operands
+ // OR'ed together.
+ assert(!isa<ConstantInt>(Divisor));
+
+ Value *OrV;
+ if (!isa<ConstantInt>(Dividend))
+ OrV = MainBuilder.CreateOr(Dividend, Divisor);
+ else
+ OrV = Divisor;
// BitMask is inverted to check if the operands are
// larger than the bypass type
OpenPOWER on IntegriCloud