[llvm] 0ad5909 - [InstCombine] Don't combine smul of i1 type constant one
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 06:05:19 PST 2023
Author: luxufan
Date: 2023-01-17T22:04:48+08:00
New Revision: 0ad5909958157c72db861b2b4b46a504c1a76ca4
URL: https://github.com/llvm/llvm-project/commit/0ad5909958157c72db861b2b4b46a504c1a76ca4
DIFF: https://github.com/llvm/llvm-project/commit/0ad5909958157c72db861b2b4b46a504c1a76ca4.diff
LOG: [InstCombine] Don't combine smul of i1 type constant one
Fixes: https://github.com/llvm/llvm-project/issues/59876
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D141214
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/smulo.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 5584332eb18e2..bbdd104b7b531 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4986,7 +4986,7 @@ Instruction *InstCombinerImpl::foldICmpWithCastOp(ICmpInst &ICmp) {
return foldICmpWithZextOrSext(ICmp);
}
-static bool isNeutralValue(Instruction::BinaryOps BinaryOp, Value *RHS) {
+static bool isNeutralValue(Instruction::BinaryOps BinaryOp, Value *RHS, bool IsSigned) {
switch (BinaryOp) {
default:
llvm_unreachable("Unsupported binary op");
@@ -4994,7 +4994,8 @@ static bool isNeutralValue(Instruction::BinaryOps BinaryOp, Value *RHS) {
case Instruction::Sub:
return match(RHS, m_Zero());
case Instruction::Mul:
- return match(RHS, m_One());
+ return !(RHS->getType()->isIntOrIntVectorTy(1) && IsSigned) &&
+ match(RHS, m_One());
}
}
@@ -5041,7 +5042,7 @@ bool InstCombinerImpl::OptimizeOverflowCheck(Instruction::BinaryOps BinaryOp,
if (auto *LHSTy = dyn_cast<VectorType>(LHS->getType()))
OverflowTy = VectorType::get(OverflowTy, LHSTy->getElementCount());
- if (isNeutralValue(BinaryOp, RHS)) {
+ if (isNeutralValue(BinaryOp, RHS, IsSigned)) {
Result = LHS;
Overflow = ConstantInt::getFalse(OverflowTy);
return true;
diff --git a/llvm/test/Transforms/InstCombine/smulo.ll b/llvm/test/Transforms/InstCombine/smulo.ll
index 8da1a5e2e7078..ce5be287ad7a7 100644
--- a/llvm/test/Transforms/InstCombine/smulo.ll
+++ b/llvm/test/Transforms/InstCombine/smulo.ll
@@ -160,7 +160,7 @@ define <2 x i1> @v2i1_ov(<2 x i1> %x, <2 x i1> %y) {
define i1 @i1_ov_by_one(i1 %x) {
; CHECK-LABEL: @i1_ov_by_one(
-; CHECK-NEXT: ret i1 false
+; CHECK-NEXT: ret i1 [[X:%.*]]
;
%m = call {i1, i1} @llvm.smul.with.overflow.i1(i1 %x, i1 1)
%ov = extractvalue {i1, i1} %m, 1
@@ -169,7 +169,7 @@ define i1 @i1_ov_by_one(i1 %x) {
define <2 x i1> @v2i1_ov_by_one(<2 x i1> %x) {
; CHECK-LABEL: @v2i1_ov_by_one(
-; CHECK-NEXT: ret <2 x i1> zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[X:%.*]]
;
%m = call {<2 x i1>, <2 x i1>} @llvm.smul.with.overflow.v2i1(<2 x i1> %x, <2 x i1> <i1 1, i1 1>)
%ov = extractvalue {<2 x i1>, <2 x i1>} %m, 1
More information about the llvm-commits
mailing list