Skip to content

Commit 2d8fc61

Browse files
committed
add disjoint to special knownbits
1 parent 2a2575a commit 2d8fc61

File tree

2 files changed

+13
-40
lines changed

2 files changed

+13
-40
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,11 @@ static Instruction *foldSelectICmpBinOp(SelectInst &SI, ICmpInst *ICI,
18581858
return NoCommonBits | AllBitsEnabled;
18591859
if (CmpRHS->isZero())
18601860
return AllCommonBits;
1861+
} else if (auto Disjoint = dyn_cast<PossiblyDisjointInst>(CmpLHS);
1862+
Disjoint->isDisjoint()) {
1863+
if (CmpRHS->isAllOnes())
1864+
return NoCommonBits | AllBitsEnabled;
1865+
return NoCommonBits;
18611866
}
18621867

18631868
return NothingSpecial;

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3763,11 +3763,7 @@ exit:
37633763
define i32 @src_or_disjoint_xor(i32 %x, i32 %y) {
37643764
; CHECK-LABEL: @src_or_disjoint_xor(
37653765
; CHECK-NEXT: entry:
3766-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint i32 [[X:%.*]], [[Y:%.*]]
3767-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR_DISJOINT]], -1
3768-
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
3769-
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 -1
3770-
; CHECK-NEXT: ret i32 [[COND]]
3766+
; CHECK-NEXT: ret i32 -1
37713767
;
37723768
entry:
37733769
%or.disjoint = or disjoint i32 %x, %y
@@ -3780,11 +3776,7 @@ entry:
37803776
define i32 @src_or_disjoint_xor_comm(i32 %x, i32 %y) {
37813777
; CHECK-LABEL: @src_or_disjoint_xor_comm(
37823778
; CHECK-NEXT: entry:
3783-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint i32 [[X:%.*]], [[Y:%.*]]
3784-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR_DISJOINT]], -1
3785-
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
3786-
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 -1
3787-
; CHECK-NEXT: ret i32 [[COND]]
3779+
; CHECK-NEXT: ret i32 -1
37883780
;
37893781
entry:
37903782
%or.disjoint = or disjoint i32 %x, %y
@@ -3797,11 +3789,7 @@ entry:
37973789
define i32 @src_or_disjoint_xor_ne(i32 %x, i32 %y) {
37983790
; CHECK-LABEL: @src_or_disjoint_xor_ne(
37993791
; CHECK-NEXT: entry:
3800-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint i32 [[X:%.*]], [[Y:%.*]]
3801-
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[OR_DISJOINT]], -1
3802-
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
3803-
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP_NOT]], i32 [[XOR]], i32 -1
3804-
; CHECK-NEXT: ret i32 [[COND]]
3792+
; CHECK-NEXT: ret i32 -1
38053793
;
38063794
entry:
38073795
%or.disjoint = or disjoint i32 %x, %y
@@ -3814,11 +3802,7 @@ entry:
38143802
define i32 @src_or_disjoint_xor_ne_comm(i32 %x, i32 %y) {
38153803
; CHECK-LABEL: @src_or_disjoint_xor_ne_comm(
38163804
; CHECK-NEXT: entry:
3817-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint i32 [[Y:%.*]], [[X:%.*]]
3818-
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[OR_DISJOINT]], -1
3819-
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y]], [[X]]
3820-
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP_NOT]], i32 [[XOR]], i32 -1
3821-
; CHECK-NEXT: ret i32 [[COND]]
3805+
; CHECK-NEXT: ret i32 -1
38223806
;
38233807
entry:
38243808
%or.disjoint = or disjoint i32 %y, %x
@@ -3831,11 +3815,7 @@ entry:
38313815
define <2 x i8> @src_or_disjoint_xor_vec(<2 x i8> %x, <2 x i8> %y) {
38323816
; CHECK-LABEL: @src_or_disjoint_xor_vec(
38333817
; CHECK-NEXT: entry:
3834-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint <2 x i8> [[X:%.*]], [[Y:%.*]]
3835-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[OR_DISJOINT]], <i8 -1, i8 -1>
3836-
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[X]], [[Y]]
3837-
; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[XOR]], <2 x i8> <i8 -1, i8 -1>
3838-
; CHECK-NEXT: ret <2 x i8> [[COND]]
3818+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
38393819
;
38403820
entry:
38413821
%or.disjoint = or disjoint <2 x i8> %x, %y
@@ -3848,11 +3828,7 @@ entry:
38483828
define <2 x i8> @src_or_disjoint_xor_comm_vec(<2 x i8> %x, <2 x i8> %y) {
38493829
; CHECK-LABEL: @src_or_disjoint_xor_comm_vec(
38503830
; CHECK-NEXT: entry:
3851-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint <2 x i8> [[X:%.*]], [[Y:%.*]]
3852-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[OR_DISJOINT]], <i8 -1, i8 -1>
3853-
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[X]], [[Y]]
3854-
; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[XOR]], <2 x i8> <i8 -1, i8 -1>
3855-
; CHECK-NEXT: ret <2 x i8> [[COND]]
3831+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
38563832
;
38573833
entry:
38583834
%or.disjoint = or disjoint <2 x i8> %x, %y
@@ -3865,11 +3841,7 @@ entry:
38653841
define <2 x i8> @src_or_disjoint_xor_ne_vec(<2 x i8> %x, <2 x i8> %y) {
38663842
; CHECK-LABEL: @src_or_disjoint_xor_ne_vec(
38673843
; CHECK-NEXT: entry:
3868-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint <2 x i8> [[X:%.*]], [[Y:%.*]]
3869-
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq <2 x i8> [[OR_DISJOINT]], <i8 -1, i8 -1>
3870-
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[X]], [[Y]]
3871-
; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP_NOT]], <2 x i8> [[XOR]], <2 x i8> <i8 -1, i8 -1>
3872-
; CHECK-NEXT: ret <2 x i8> [[COND]]
3844+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
38733845
;
38743846
entry:
38753847
%or.disjoint = or disjoint <2 x i8> %x, %y
@@ -3882,11 +3854,7 @@ entry:
38823854
define <2 x i8> @src_or_disjoint_xor_ne_comm_vec(<2 x i8> %x, <2 x i8> %y) {
38833855
; CHECK-LABEL: @src_or_disjoint_xor_ne_comm_vec(
38843856
; CHECK-NEXT: entry:
3885-
; CHECK-NEXT: [[OR_DISJOINT:%.*]] = or disjoint <2 x i8> [[Y:%.*]], [[X:%.*]]
3886-
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq <2 x i8> [[OR_DISJOINT]], <i8 -1, i8 -1>
3887-
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[Y]], [[X]]
3888-
; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP_NOT]], <2 x i8> [[XOR]], <2 x i8> <i8 -1, i8 -1>
3889-
; CHECK-NEXT: ret <2 x i8> [[COND]]
3857+
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
38903858
;
38913859
entry:
38923860
%or.disjoint = or disjoint <2 x i8> %y, %x

0 commit comments

Comments
 (0)