summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp11
-rw-r--r--llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll9
2 files changed, 16 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index b650971624a..a56a37a618b 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -416,10 +416,13 @@ static void processOverflowIntrinsic(WithOverflowInst *WO) {
IRBuilder<> B(WO);
Value *NewOp = B.CreateBinOp(
WO->getBinaryOp(), WO->getLHS(), WO->getRHS(), WO->getName());
- if (WO->isSigned())
- cast<Instruction>(NewOp)->setHasNoSignedWrap();
- else
- cast<Instruction>(NewOp)->setHasNoUnsignedWrap();
+ // Constant-holing could have happened.
+ if (auto *Inst = dyn_cast<Instruction>(NewOp)) {
+ if (WO->isSigned())
+ Inst->setHasNoSignedWrap();
+ else
+ Inst->setHasNoUnsignedWrap();
+ }
Value *NewI = B.CreateInsertValue(UndefValue::get(WO->getType()), NewOp, 0);
NewI = B.CreateInsertValue(NewI, ConstantInt::getFalse(WO->getContext()), 1);
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll b/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll
index db758b8459b..9edf4789b8e 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll
@@ -715,3 +715,12 @@ while.end: ; preds = %while.cond, %cont
cleanup2: ; preds = %while.end
ret void
}
+
+define { i8, i1 } @signed_mul_constant_folding() {
+; CHECK-LABEL: @signed_mul_constant_folding(
+; CHECK-NEXT: ret { i8, i1 } { i8 2, i1 false }
+ %mul = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 1, i8 2)
+ ret { i8, i1 } %mul
+}
+
+declare { i8, i1 } @llvm.umul.with.overflow.i8(i8, i8)
OpenPOWER on IntegriCloud