summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-08-24 17:20:50 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-08-24 17:20:50 +0000
commitbdc6feb28f528ee3a365ca97577f7312ffa0dc65 (patch)
tree8fc5cf6a8835cc178d70cd0ee29af2513f5c9161 /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
parent10c469f2ae76868106ec8bc8fbac13e0f26552f7 (diff)
Notes
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index c6233a68847d..2f1325e80d2f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -216,7 +216,11 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
if (match(&I, m_Mul(m_Value(NewOp), m_Constant(C1)))) {
// Replace X*(2^C) with X << C, where C is either a scalar or a vector.
- if (Constant *NewCst = getLogBase2(NewOp->getType(), C1)) {
+ // Note that we need to sanitize undef multipliers to 1,
+ // to avoid introducing poison.
+ Constant *SafeC1 = Constant::replaceUndefsWith(
+ C1, ConstantInt::get(C1->getType()->getScalarType(), 1));
+ if (Constant *NewCst = getLogBase2(NewOp->getType(), SafeC1)) {
BinaryOperator *Shl = BinaryOperator::CreateShl(NewOp, NewCst);
if (I.hasNoUnsignedWrap())