summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2018-02-08 14:46:10 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2018-02-08 14:46:10 +0000
commit94cc89d5f2960e78e98e97a9224a8e28f972318c (patch)
tree79cf6492e9ec0cb789cb782505a35b7525b678bf /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
parent3a98e51823beaefa63016814c8e92e46a31599fc (diff)
downloadbcm5719-llvm-94cc89d5f2960e78e98e97a9224a8e28f972318c.tar.gz
bcm5719-llvm-94cc89d5f2960e78e98e97a9224a8e28f972318c.zip
[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
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