Skip to content

Commit c74db55

Browse files
committed
[InstSimplify] allow vector folds for icmp Pred (1 << X), 0x80
1 parent 5765edb commit c74db55

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,15 +3019,19 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate Pred, Value *LHS,
30193019
return ConstantInt::getTrue(RHS->getContext());
30203020
}
30213021
}
3022-
if (CIVal->isSignMask() && CI2Val->isOneValue()) {
3023-
if (Pred == ICmpInst::ICMP_UGT)
3024-
return ConstantInt::getFalse(RHS->getContext());
3025-
if (Pred == ICmpInst::ICMP_ULE)
3026-
return ConstantInt::getTrue(RHS->getContext());
3027-
}
30283022
}
30293023
}
30303024

3025+
// TODO: This is overly constrained. LHS can be any power-of-2.
3026+
// (1 << X) >u 0x8000 --> false
3027+
// (1 << X) <=u 0x8000 --> true
3028+
if (match(LHS, m_Shl(m_One(), m_Value())) && match(RHS, m_SignMask())) {
3029+
if (Pred == ICmpInst::ICMP_UGT)
3030+
return ConstantInt::getFalse(GetCompareTy(RHS));
3031+
if (Pred == ICmpInst::ICMP_ULE)
3032+
return ConstantInt::getTrue(GetCompareTy(RHS));
3033+
}
3034+
30313035
if (MaxRecurse && LBO && RBO && LBO->getOpcode() == RBO->getOpcode() &&
30323036
LBO->getOperand(1) == RBO->getOperand(1)) {
30333037
switch (LBO->getOpcode()) {

llvm/test/Transforms/InstSimplify/compare.ll

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,9 +1479,7 @@ define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) {
14791479

14801480
define <2 x i1> @icmp_shl_1_ugt_signmask(<2 x i8> %V) {
14811481
; CHECK-LABEL: @icmp_shl_1_ugt_signmask(
1482-
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i8> <i8 1, i8 1>, [[V:%.*]]
1483-
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[SHL]], <i8 -128, i8 -128>
1484-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1482+
; CHECK-NEXT: ret <2 x i1> zeroinitializer
14851483
;
14861484
%shl = shl <2 x i8> <i8 1, i8 1>, %V
14871485
%cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 128>
@@ -1490,9 +1488,7 @@ define <2 x i1> @icmp_shl_1_ugt_signmask(<2 x i8> %V) {
14901488

14911489
define <2 x i1> @icmp_shl_1_ugt_signmask_undef(<2 x i8> %V) {
14921490
; CHECK-LABEL: @icmp_shl_1_ugt_signmask_undef(
1493-
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i8> <i8 1, i8 1>, [[V:%.*]]
1494-
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[SHL]], <i8 -128, i8 undef>
1495-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1491+
; CHECK-NEXT: ret <2 x i1> zeroinitializer
14961492
;
14971493
%shl = shl <2 x i8> <i8 1, i8 1>, %V
14981494
%cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 undef>
@@ -1501,9 +1497,7 @@ define <2 x i1> @icmp_shl_1_ugt_signmask_undef(<2 x i8> %V) {
15011497

15021498
define <2 x i1> @icmp_shl_1_ugt_signmask_undef2(<2 x i8> %V) {
15031499
; CHECK-LABEL: @icmp_shl_1_ugt_signmask_undef2(
1504-
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i8> <i8 1, i8 undef>, [[V:%.*]]
1505-
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[SHL]], <i8 undef, i8 -128>
1506-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1500+
; CHECK-NEXT: ret <2 x i1> zeroinitializer
15071501
;
15081502
%shl = shl <2 x i8> <i8 1, i8 undef>, %V
15091503
%cmp = icmp ugt <2 x i8> %shl, <i8 undef, i8 128>
@@ -1521,9 +1515,7 @@ define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) {
15211515

15221516
define <2 x i1> @icmp_shl_1_ule_signmask(<2 x i8> %V) {
15231517
; CHECK-LABEL: @icmp_shl_1_ule_signmask(
1524-
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i8> <i8 1, i8 1>, [[V:%.*]]
1525-
; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i8> [[SHL]], <i8 -128, i8 -128>
1526-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1518+
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
15271519
;
15281520
%shl = shl <2 x i8> <i8 1, i8 1>, %V
15291521
%cmp = icmp ule <2 x i8> %shl, <i8 128, i8 128>
@@ -1532,9 +1524,7 @@ define <2 x i1> @icmp_shl_1_ule_signmask(<2 x i8> %V) {
15321524

15331525
define <2 x i1> @icmp_shl_1_ule_signmask_undef(<2 x i8> %V) {
15341526
; CHECK-LABEL: @icmp_shl_1_ule_signmask_undef(
1535-
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i8> <i8 1, i8 1>, [[V:%.*]]
1536-
; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i8> [[SHL]], <i8 -128, i8 undef>
1537-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1527+
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
15381528
;
15391529
%shl = shl <2 x i8> <i8 1, i8 1>, %V
15401530
%cmp = icmp ule <2 x i8> %shl, <i8 128, i8 undef>
@@ -1543,9 +1533,7 @@ define <2 x i1> @icmp_shl_1_ule_signmask_undef(<2 x i8> %V) {
15431533

15441534
define <2 x i1> @icmp_shl_1_ule_signmask_undef2(<2 x i8> %V) {
15451535
; CHECK-LABEL: @icmp_shl_1_ule_signmask_undef2(
1546-
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i8> <i8 1, i8 undef>, [[V:%.*]]
1547-
; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i8> [[SHL]], <i8 undef, i8 -128>
1548-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1536+
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
15491537
;
15501538
%shl = shl <2 x i8> <i8 1, i8 undef>, %V
15511539
%cmp = icmp ule <2 x i8> %shl, <i8 undef, i8 128>

0 commit comments

Comments
 (0)