Skip to content

Commit 0ad5909

Browse files
author
luxufan
committed
[InstCombine] Don't combine smul of i1 type constant one
Fixes: #59876 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D141214
1 parent 774275d commit 0ad5909

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4986,15 +4986,16 @@ Instruction *InstCombinerImpl::foldICmpWithCastOp(ICmpInst &ICmp) {
49864986
return foldICmpWithZextOrSext(ICmp);
49874987
}
49884988

4989-
static bool isNeutralValue(Instruction::BinaryOps BinaryOp, Value *RHS) {
4989+
static bool isNeutralValue(Instruction::BinaryOps BinaryOp, Value *RHS, bool IsSigned) {
49904990
switch (BinaryOp) {
49914991
default:
49924992
llvm_unreachable("Unsupported binary op");
49934993
case Instruction::Add:
49944994
case Instruction::Sub:
49954995
return match(RHS, m_Zero());
49964996
case Instruction::Mul:
4997-
return match(RHS, m_One());
4997+
return !(RHS->getType()->isIntOrIntVectorTy(1) && IsSigned) &&
4998+
match(RHS, m_One());
49984999
}
49995000
}
50005001

@@ -5041,7 +5042,7 @@ bool InstCombinerImpl::OptimizeOverflowCheck(Instruction::BinaryOps BinaryOp,
50415042
if (auto *LHSTy = dyn_cast<VectorType>(LHS->getType()))
50425043
OverflowTy = VectorType::get(OverflowTy, LHSTy->getElementCount());
50435044

5044-
if (isNeutralValue(BinaryOp, RHS)) {
5045+
if (isNeutralValue(BinaryOp, RHS, IsSigned)) {
50455046
Result = LHS;
50465047
Overflow = ConstantInt::getFalse(OverflowTy);
50475048
return true;

llvm/test/Transforms/InstCombine/smulo.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ define <2 x i1> @v2i1_ov(<2 x i1> %x, <2 x i1> %y) {
160160

161161
define i1 @i1_ov_by_one(i1 %x) {
162162
; CHECK-LABEL: @i1_ov_by_one(
163-
; CHECK-NEXT: ret i1 false
163+
; CHECK-NEXT: ret i1 [[X:%.*]]
164164
;
165165
%m = call {i1, i1} @llvm.smul.with.overflow.i1(i1 %x, i1 1)
166166
%ov = extractvalue {i1, i1} %m, 1
@@ -169,7 +169,7 @@ define i1 @i1_ov_by_one(i1 %x) {
169169

170170
define <2 x i1> @v2i1_ov_by_one(<2 x i1> %x) {
171171
; CHECK-LABEL: @v2i1_ov_by_one(
172-
; CHECK-NEXT: ret <2 x i1> zeroinitializer
172+
; CHECK-NEXT: ret <2 x i1> [[X:%.*]]
173173
;
174174
%m = call {<2 x i1>, <2 x i1>} @llvm.smul.with.overflow.v2i1(<2 x i1> %x, <2 x i1> <i1 1, i1 1>)
175175
%ov = extractvalue {<2 x i1>, <2 x i1>} %m, 1

0 commit comments

Comments
 (0)