From: Roman Lebedev Date: Wed, 17 Apr 2019 06:35:07 +0000 (+0000) Subject: [CVP] processOverflowIntrinsic(): don't crash if constant-holding happened X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec0d5b2a31a354016a946fb24e24005d0d39b297;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358559 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index b650971624a..a56a37a618b 100644 --- a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/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(NewOp)->setHasNoSignedWrap(); - else - cast(NewOp)->setHasNoUnsignedWrap(); + // Constant-holing could have happened. + if (auto *Inst = dyn_cast(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/test/Transforms/CorrelatedValuePropagation/overflows.ll b/test/Transforms/CorrelatedValuePropagation/overflows.ll index db758b8459b..9edf4789b8e 100644 --- a/test/Transforms/CorrelatedValuePropagation/overflows.ll +++ b/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)