Skip to content

Commit d8bc4de

Browse files
committed
[X86] Fold cmpeq/ne(or(X,Y),X) --> cmpeq/ne(and(~X,Y),0) on non-BMI targets (PR44136)
Followup to D100177, enable the fold for non-BMI targets as well.
1 parent b7578f9 commit d8bc4de

File tree

6 files changed

+23
-45
lines changed

6 files changed

+23
-45
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48165,7 +48165,7 @@ static SDValue combineSetCC(SDNode *N, SelectionDAG &DAG,
4816548165

4816648166
// cmpeq(or(X,Y),X) --> cmpeq(and(~X,Y),0)
4816748167
// cmpne(or(X,Y),X) --> cmpne(and(~X,Y),0)
48168-
if (OpVT.isScalarInteger() && Subtarget.hasBMI()) {
48168+
if (OpVT.isScalarInteger()) {
4816948169
auto MatchOrCmpEq = [&](SDValue N0, SDValue N1) {
4817048170
if (N0.getOpcode() == ISD::OR && N0->hasOneUse()) {
4817148171
if (N0.getOperand(0) == N1)

llvm/test/CodeGen/X86/avx512-cmp.ll

+3-6
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,10 @@ B:
155155
define i32 @test10(i64 %b, i64 %c, i1 %d) {
156156
; ALL-LABEL: test10:
157157
; ALL: ## %bb.0:
158-
; ALL-NEXT: movl %edx, %eax
159-
; ALL-NEXT: andb $1, %al
160158
; ALL-NEXT: cmpq %rsi, %rdi
161-
; ALL-NEXT: sete %cl
162-
; ALL-NEXT: orb %dl, %cl
163-
; ALL-NEXT: andb $1, %cl
164-
; ALL-NEXT: cmpb %cl, %al
159+
; ALL-NEXT: sete %al
160+
; ALL-NEXT: notb %dl
161+
; ALL-NEXT: testb %al, %dl
165162
; ALL-NEXT: je LBB8_1
166163
; ALL-NEXT: ## %bb.2: ## %if.end.i
167164
; ALL-NEXT: movl $6, %eax

llvm/test/CodeGen/X86/pr27202.ll

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ define i1 @foo_pgso(i32 %i) !prof !14 {
3333
define zeroext i1 @g(i32 %x) optsize {
3434
; CHECK-LABEL: g:
3535
; CHECK: # %bb.0:
36-
; CHECK-NEXT: orl $1, %edi
37-
; CHECK-NEXT: cmpl $1, %edi
36+
; CHECK-NEXT: testl $-2, %edi
3837
; CHECK-NEXT: sete %al
3938
; CHECK-NEXT: retq
4039
%t0 = or i32 %x, 1

llvm/test/CodeGen/X86/ragreedy-hoist-spill.ll

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ define i8* @SyFgets(i8* %line, i64 %length, i64 %fid) {
3737
; CHECK-NEXT: .cfi_offset %r14, -32
3838
; CHECK-NEXT: .cfi_offset %r15, -24
3939
; CHECK-NEXT: .cfi_offset %rbp, -16
40-
; CHECK-NEXT: movq %rdx, %rax
41-
; CHECK-NEXT: orq $2, %rax
42-
; CHECK-NEXT: cmpq $2, %rax
40+
; CHECK-NEXT: testq $-3, %rdx
4341
; CHECK-NEXT: jne LBB0_4
4442
; CHECK-NEXT: ## %bb.1: ## %if.end
4543
; CHECK-NEXT: xorl %eax, %eax

llvm/test/CodeGen/X86/setcc-logic.ll

+16-30
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ define i1 @and_icmps_const_1bit_diff_common_op(i32 %x, i32 %y) {
612612
define i1 @or_cmp_eq_i64(i64 %x, i64 %y) {
613613
; NOBMI-LABEL: or_cmp_eq_i64:
614614
; NOBMI: # %bb.0:
615-
; NOBMI-NEXT: orq %rdi, %rsi
616-
; NOBMI-NEXT: cmpq %rdi, %rsi
615+
; NOBMI-NEXT: notq %rdi
616+
; NOBMI-NEXT: testq %rsi, %rdi
617617
; NOBMI-NEXT: sete %al
618618
; NOBMI-NEXT: retq
619619
;
@@ -630,8 +630,8 @@ define i1 @or_cmp_eq_i64(i64 %x, i64 %y) {
630630
define i1 @or_cmp_ne_i32(i32 %x, i32 %y) {
631631
; NOBMI-LABEL: or_cmp_ne_i32:
632632
; NOBMI: # %bb.0:
633-
; NOBMI-NEXT: orl %esi, %edi
634-
; NOBMI-NEXT: cmpl %esi, %edi
633+
; NOBMI-NEXT: notl %esi
634+
; NOBMI-NEXT: testl %edi, %esi
635635
; NOBMI-NEXT: setne %al
636636
; NOBMI-NEXT: retq
637637
;
@@ -646,38 +646,24 @@ define i1 @or_cmp_ne_i32(i32 %x, i32 %y) {
646646
}
647647

648648
define i1 @or_cmp_eq_i16(i16 zeroext %x, i16 zeroext %y) {
649-
; NOBMI-LABEL: or_cmp_eq_i16:
650-
; NOBMI: # %bb.0:
651-
; NOBMI-NEXT: orl %edi, %esi
652-
; NOBMI-NEXT: cmpw %si, %di
653-
; NOBMI-NEXT: sete %al
654-
; NOBMI-NEXT: retq
655-
;
656-
; BMI-LABEL: or_cmp_eq_i16:
657-
; BMI: # %bb.0:
658-
; BMI-NEXT: notl %edi
659-
; BMI-NEXT: testw %si, %di
660-
; BMI-NEXT: sete %al
661-
; BMI-NEXT: retq
649+
; CHECK-LABEL: or_cmp_eq_i16:
650+
; CHECK: # %bb.0:
651+
; CHECK-NEXT: notl %edi
652+
; CHECK-NEXT: testw %si, %di
653+
; CHECK-NEXT: sete %al
654+
; CHECK-NEXT: retq
662655
%o = or i16 %x, %y
663656
%c = icmp eq i16 %x, %o
664657
ret i1 %c
665658
}
666659

667660
define i1 @or_cmp_ne_i8(i8 zeroext %x, i8 zeroext %y) {
668-
; NOBMI-LABEL: or_cmp_ne_i8:
669-
; NOBMI: # %bb.0:
670-
; NOBMI-NEXT: orl %esi, %edi
671-
; NOBMI-NEXT: cmpb %dil, %sil
672-
; NOBMI-NEXT: setne %al
673-
; NOBMI-NEXT: retq
674-
;
675-
; BMI-LABEL: or_cmp_ne_i8:
676-
; BMI: # %bb.0:
677-
; BMI-NEXT: notb %sil
678-
; BMI-NEXT: testb %dil, %sil
679-
; BMI-NEXT: setne %al
680-
; BMI-NEXT: retq
661+
; CHECK-LABEL: or_cmp_ne_i8:
662+
; CHECK: # %bb.0:
663+
; CHECK-NEXT: notb %sil
664+
; CHECK-NEXT: testb %dil, %sil
665+
; CHECK-NEXT: setne %al
666+
; CHECK-NEXT: retq
681667
%o = or i8 %x, %y
682668
%c = icmp ne i8 %y, %o
683669
ret i1 %c

llvm/test/CodeGen/X86/switch-or.ll

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
; CHECK-LABEL: test1
55
; CHECK: orl $2
66
; CHECK-NEXT: cmpl $6
7-
87
define void @test1(i32 %variable) nounwind {
98
entry:
109
switch i32 %variable, label %if.end [
@@ -21,8 +20,7 @@ if.end:
2120
}
2221

2322
; CHECK-LABEL: test2
24-
; CHECK: orl $-2147483648
25-
; CHECK-NEXT: cmpl $-2147483648
23+
; CHECK: testl $2147483647
2624
define void @test2(i32 %variable) nounwind {
2725
entry:
2826
switch i32 %variable, label %if.end [

0 commit comments

Comments
 (0)