Skip to content

Commit b231274

Browse files
committed
InstCombine: teach foldICmpAddConstant about samesign
There are missed optimizations on samesign, due to the predicate being canonicalized into an equality before we get to our function.
1 parent cd008a7 commit b231274

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,7 +3118,7 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
31183118

31193119
Value *Op0, *Op1;
31203120
Instruction *Ext0, *Ext1;
3121-
const CmpInst::Predicate Pred = Cmp.getPredicate();
3121+
const CmpPredicate Pred = Cmp.getCmpPredicate();
31223122
if (match(Add,
31233123
m_Add(m_CombineAnd(m_Instruction(Ext0), m_ZExtOrSExt(m_Value(Op0))),
31243124
m_CombineAnd(m_Instruction(Ext1),
@@ -3133,7 +3133,7 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
31333133
Res += APInt(BW, isa<ZExtInst>(Ext0) ? 1 : -1, /*isSigned=*/true);
31343134
if (Op1Val)
31353135
Res += APInt(BW, isa<ZExtInst>(Ext1) ? 1 : -1, /*isSigned=*/true);
3136-
return ICmpInst::compare(Res, C, Pred);
3136+
return ICmpInst::compare(Res, C, Pred.getPreferredSignedPredicate());
31373137
};
31383138

31393139
Table[0] = ComputeTable(false, false);

llvm/test/Transforms/InstCombine/icmp-add.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,7 @@ bb:
13361336
define i1 @test_sext_sext_cvt_2_gt_icmp(i1 %arg, i1 %arg1) {
13371337
; CHECK-LABEL: @test_sext_sext_cvt_2_gt_icmp(
13381338
; CHECK-NEXT: bb:
1339-
; CHECK-NEXT: [[I4:%.*]] = or i1 [[ARG1:%.*]], [[ARG:%.*]]
1340-
; CHECK-NEXT: ret i1 [[I4]]
1339+
; CHECK-NEXT: ret i1 false
13411340
;
13421341
bb:
13431342
%i = sext i1 %arg to i32
@@ -1476,9 +1475,7 @@ bb:
14761475
define i1 @test_zext_sext_cvt_2_gt_icmp(i1 %arg, i1 %arg1) {
14771476
; CHECK-LABEL: @test_zext_sext_cvt_2_gt_icmp(
14781477
; CHECK-NEXT: bb:
1479-
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[ARG:%.*]], true
1480-
; CHECK-NEXT: [[I4:%.*]] = and i1 [[ARG1:%.*]], [[TMP0]]
1481-
; CHECK-NEXT: ret i1 [[I4]]
1478+
; CHECK-NEXT: ret i1 false
14821479
;
14831480
bb:
14841481
%i = zext i1 %arg to i32

0 commit comments

Comments
 (0)