]> granicus.if.org Git - llvm/commitdiff
[CVP] processOverflowIntrinsic(): don't crash if constant-holding happened
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 17 Apr 2019 06:35:07 +0000 (06:35 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 17 Apr 2019 06:35:07 +0000 (06:35 +0000)
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

lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
test/Transforms/CorrelatedValuePropagation/overflows.ll

index b650971624a75146bcedd0f755e9bab64910f7ae..a56a37a618bc63d86c1d03cfd923c46dfdfa1425 100644 (file)
@@ -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);
index db758b8459b7fca1a3568efc097665e453dbf38d..9edf4789b8e4ec92d26cb8bc963a4803ad4986e7 100644 (file)
@@ -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)