summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2018-02-08 15:19:38 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2018-02-08 15:19:38 +0000
commit2a90acd17a87b5de078f9ba2f31193ae72b2a6f3 (patch)
tree6a1686cf689eb322bd3aa76bd35e03274d9e730d /llvm/lib/Transforms
parentcfa5c03039227db73df635e8f13f391a34f36e68 (diff)
downloadbcm5719-llvm-2a90acd17a87b5de078f9ba2f31193ae72b2a6f3.tar.gz
bcm5719-llvm-2a90acd17a87b5de078f9ba2f31193ae72b2a6f3.zip
[InstCombine] Fix issue with X udiv (POW2_C1 << N) for non-splat constant vectors
foldUDivShl was assuming that the input was a scalar or a splat constant llvm-svn: 324613
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 9efc797d464..9bbabd9203b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1081,12 +1081,14 @@ static Instruction *foldUDivShl(Value *Op0, Value *Op1, const BinaryOperator &I,
if (!match(Op1, m_ZExt(m_Value(ShiftLeft))))
ShiftLeft = Op1;
- const APInt *CI;
+ Constant *CI;
Value *N;
- if (!match(ShiftLeft, m_Shl(m_APInt(CI), m_Value(N))))
+ if (!match(ShiftLeft, m_Shl(m_Constant(CI), m_Value(N))))
llvm_unreachable("match should never fail here!");
- if (*CI != 1)
- N = IC.Builder.CreateAdd(N, ConstantInt::get(N->getType(), CI->logBase2()));
+ Constant *Log2Base = getLogBase2(N->getType(), CI);
+ if (!Log2Base)
+ llvm_unreachable("getLogBase2 should never fail here!");
+ N = IC.Builder.CreateAdd(N, Log2Base);
if (Op1 != ShiftLeft)
N = IC.Builder.CreateZExt(N, Op1->getType());
BinaryOperator *LShr = BinaryOperator::CreateLShr(Op0, N);
OpenPOWER on IntegriCloud