summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index e751c64caae..9efc797d464 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1055,9 +1055,10 @@ struct UDivFoldAction {
// X udiv 2^C -> X >> C
static Instruction *foldUDivPow2Cst(Value *Op0, Value *Op1,
const BinaryOperator &I, InstCombiner &IC) {
- const APInt &C = cast<Constant>(Op1)->getUniqueInteger();
- BinaryOperator *LShr = BinaryOperator::CreateLShr(
- Op0, ConstantInt::get(Op0->getType(), C.logBase2()));
+ Constant *C1 = getLogBase2(Op0->getType(), cast<Constant>(Op1));
+ if (!C1)
+ llvm_unreachable("Failed to constant fold udiv -> logbase2");
+ BinaryOperator *LShr = BinaryOperator::CreateLShr(Op0, C1);
if (I.isExact())
LShr->setIsExact();
return LShr;
OpenPOWER on IntegriCloud