Skip to content

Commit 0080645

Browse files
committed
[CVP] processOverflowIntrinsic(): don't crash if constant-holding happened
As reported by Mikael Holmén in post-commit review in https://reviews.llvm.org/D60791#1469765 llvm-svn: 358559
1 parent df44ff1 commit 0080645

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,13 @@ static void processOverflowIntrinsic(WithOverflowInst *WO) {
416416
IRBuilder<> B(WO);
417417
Value *NewOp = B.CreateBinOp(
418418
WO->getBinaryOp(), WO->getLHS(), WO->getRHS(), WO->getName());
419-
if (WO->isSigned())
420-
cast<Instruction>(NewOp)->setHasNoSignedWrap();
421-
else
422-
cast<Instruction>(NewOp)->setHasNoUnsignedWrap();
419+
// Constant-holing could have happened.
420+
if (auto *Inst = dyn_cast<Instruction>(NewOp)) {
421+
if (WO->isSigned())
422+
Inst->setHasNoSignedWrap();
423+
else
424+
Inst->setHasNoUnsignedWrap();
425+
}
423426

424427
Value *NewI = B.CreateInsertValue(UndefValue::get(WO->getType()), NewOp, 0);
425428
NewI = B.CreateInsertValue(NewI, ConstantInt::getFalse(WO->getContext()), 1);

llvm/test/Transforms/CorrelatedValuePropagation/overflows.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,12 @@ while.end: ; preds = %while.cond, %cont
715715
cleanup2: ; preds = %while.end
716716
ret void
717717
}
718+
719+
define { i8, i1 } @signed_mul_constant_folding() {
720+
; CHECK-LABEL: @signed_mul_constant_folding(
721+
; CHECK-NEXT: ret { i8, i1 } { i8 2, i1 false }
722+
%mul = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 1, i8 2)
723+
ret { i8, i1 } %mul
724+
}
725+
726+
declare { i8, i1 } @llvm.umul.with.overflow.i8(i8, i8)

0 commit comments

Comments
 (0)