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);
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)