From 94cc89d5f2960e78e98e97a9224a8e28f972318c Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 8 Feb 2018 14:46:10 +0000 Subject: [InstCombine] Fix issue with X udiv 2^C -> X >> C for non-splat constant vectors foldUDivPow2Cst was assuming that the input was a scalar or a splat constant llvm-svn: 324608 --- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp') 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(Op1)->getUniqueInteger(); - BinaryOperator *LShr = BinaryOperator::CreateLShr( - Op0, ConstantInt::get(Op0->getType(), C.logBase2())); + Constant *C1 = getLogBase2(Op0->getType(), cast(Op1)); + if (!C1) + llvm_unreachable("Failed to constant fold udiv -> logbase2"); + BinaryOperator *LShr = BinaryOperator::CreateLShr(Op0, C1); if (I.isExact()) LShr->setIsExact(); return LShr; -- cgit v1.2.3