aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/InstCombine/InstCombineMulDivRem.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index e104a0a979..5eba463ec0 100644
--- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -462,11 +462,11 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
}
}
- // Udiv ((Lshl x, c1) , c2) -> x / (C1 * 1<<C2);
- if (Constant *C = dyn_cast<Constant>(Op1)) {
+ // Udiv ((Lshl x, C1) , C2) -> x / (C2 * 1<<C1);
+ if (ConstantInt *C2 = dyn_cast<ConstantInt>(Op1)) {
Value *X = 0, *C1 = 0;
- if (match(Op0, m_LShr(m_Value(X), m_Value(C1)))) {
- uint64_t NC = cast<ConstantInt>(C)->getZExtValue() *
+ if (match(Op0, m_LShr(m_Value(X), m_Value(C1))) && C2->getBitWidth() < 65) {
+ uint64_t NC = cast<ConstantInt>(C2)->getZExtValue() *
(1<< cast<ConstantInt>(C1)->getZExtValue());
return BinaryOperator::CreateUDiv(X, ConstantInt::get(I.getType(), NC));
}
@@ -543,11 +543,11 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
ConstantExpr::getNeg(RHS));
}
- // Sdiv ((Ashl x, c1) , c2) -> x / (C1 * 1<<C2);
- if (Constant *C = dyn_cast<Constant>(Op1)) {
+ // Sdiv ((Ashl x, C1) , C2) -> x / (C2 * 1<<C1);
+ if (ConstantInt *C2 = dyn_cast<ConstantInt>(Op1)) {
Value *X = 0, *C1 = 0;
- if (match(Op0, m_AShr(m_Value(X), m_Value(C1)))) {
- uint64_t NC = cast<ConstantInt>(C)->getZExtValue() *
+ if (match(Op0, m_AShr(m_Value(X), m_Value(C1))) && C2->getBitWidth() < 65) {
+ uint64_t NC = cast<ConstantInt>(C2)->getZExtValue() *
(1<< cast<ConstantInt>(C1)->getZExtValue());
return BinaryOperator::CreateSDiv(X, ConstantInt::get(I.getType(), NC));
}