1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[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.
This commit is contained in:
Simon Pilgrim 2021-04-09 16:10:57 +01:00
parent d4bbffc9a1
commit 6499558743
6 changed files with 23 additions and 45 deletions

View File

@ -48165,7 +48165,7 @@ static SDValue combineSetCC(SDNode *N, SelectionDAG &DAG,
// cmpeq(or(X,Y),X) --> cmpeq(and(~X,Y),0) // cmpeq(or(X,Y),X) --> cmpeq(and(~X,Y),0)
// cmpne(or(X,Y),X) --> cmpne(and(~X,Y),0) // cmpne(or(X,Y),X) --> cmpne(and(~X,Y),0)
if (OpVT.isScalarInteger() && Subtarget.hasBMI()) { if (OpVT.isScalarInteger()) {
auto MatchOrCmpEq = [&](SDValue N0, SDValue N1) { auto MatchOrCmpEq = [&](SDValue N0, SDValue N1) {
if (N0.getOpcode() == ISD::OR && N0->hasOneUse()) { if (N0.getOpcode() == ISD::OR && N0->hasOneUse()) {
if (N0.getOperand(0) == N1) if (N0.getOperand(0) == N1)

View File

@ -155,13 +155,10 @@ B:
define i32 @test10(i64 %b, i64 %c, i1 %d) { define i32 @test10(i64 %b, i64 %c, i1 %d) {
; ALL-LABEL: test10: ; ALL-LABEL: test10:
; ALL: ## %bb.0: ; ALL: ## %bb.0:
; ALL-NEXT: movl %edx, %eax
; ALL-NEXT: andb $1, %al
; ALL-NEXT: cmpq %rsi, %rdi ; ALL-NEXT: cmpq %rsi, %rdi
; ALL-NEXT: sete %cl ; ALL-NEXT: sete %al
; ALL-NEXT: orb %dl, %cl ; ALL-NEXT: notb %dl
; ALL-NEXT: andb $1, %cl ; ALL-NEXT: testb %al, %dl
; ALL-NEXT: cmpb %cl, %al
; ALL-NEXT: je LBB8_1 ; ALL-NEXT: je LBB8_1
; ALL-NEXT: ## %bb.2: ## %if.end.i ; ALL-NEXT: ## %bb.2: ## %if.end.i
; ALL-NEXT: movl $6, %eax ; ALL-NEXT: movl $6, %eax

View File

@ -33,8 +33,7 @@ define i1 @foo_pgso(i32 %i) !prof !14 {
define zeroext i1 @g(i32 %x) optsize { define zeroext i1 @g(i32 %x) optsize {
; CHECK-LABEL: g: ; CHECK-LABEL: g:
; CHECK: # %bb.0: ; CHECK: # %bb.0:
; CHECK-NEXT: orl $1, %edi ; CHECK-NEXT: testl $-2, %edi
; CHECK-NEXT: cmpl $1, %edi
; CHECK-NEXT: sete %al ; CHECK-NEXT: sete %al
; CHECK-NEXT: retq ; CHECK-NEXT: retq
%t0 = or i32 %x, 1 %t0 = or i32 %x, 1

View File

@ -37,9 +37,7 @@ define i8* @SyFgets(i8* %line, i64 %length, i64 %fid) {
; CHECK-NEXT: .cfi_offset %r14, -32 ; CHECK-NEXT: .cfi_offset %r14, -32
; CHECK-NEXT: .cfi_offset %r15, -24 ; CHECK-NEXT: .cfi_offset %r15, -24
; CHECK-NEXT: .cfi_offset %rbp, -16 ; CHECK-NEXT: .cfi_offset %rbp, -16
; CHECK-NEXT: movq %rdx, %rax ; CHECK-NEXT: testq $-3, %rdx
; CHECK-NEXT: orq $2, %rax
; CHECK-NEXT: cmpq $2, %rax
; CHECK-NEXT: jne LBB0_4 ; CHECK-NEXT: jne LBB0_4
; CHECK-NEXT: ## %bb.1: ## %if.end ; CHECK-NEXT: ## %bb.1: ## %if.end
; CHECK-NEXT: xorl %eax, %eax ; CHECK-NEXT: xorl %eax, %eax

View File

@ -612,8 +612,8 @@ define i1 @and_icmps_const_1bit_diff_common_op(i32 %x, i32 %y) {
define i1 @or_cmp_eq_i64(i64 %x, i64 %y) { define i1 @or_cmp_eq_i64(i64 %x, i64 %y) {
; NOBMI-LABEL: or_cmp_eq_i64: ; NOBMI-LABEL: or_cmp_eq_i64:
; NOBMI: # %bb.0: ; NOBMI: # %bb.0:
; NOBMI-NEXT: orq %rdi, %rsi ; NOBMI-NEXT: notq %rdi
; NOBMI-NEXT: cmpq %rdi, %rsi ; NOBMI-NEXT: testq %rsi, %rdi
; NOBMI-NEXT: sete %al ; NOBMI-NEXT: sete %al
; NOBMI-NEXT: retq ; NOBMI-NEXT: retq
; ;
@ -630,8 +630,8 @@ define i1 @or_cmp_eq_i64(i64 %x, i64 %y) {
define i1 @or_cmp_ne_i32(i32 %x, i32 %y) { define i1 @or_cmp_ne_i32(i32 %x, i32 %y) {
; NOBMI-LABEL: or_cmp_ne_i32: ; NOBMI-LABEL: or_cmp_ne_i32:
; NOBMI: # %bb.0: ; NOBMI: # %bb.0:
; NOBMI-NEXT: orl %esi, %edi ; NOBMI-NEXT: notl %esi
; NOBMI-NEXT: cmpl %esi, %edi ; NOBMI-NEXT: testl %edi, %esi
; NOBMI-NEXT: setne %al ; NOBMI-NEXT: setne %al
; NOBMI-NEXT: retq ; NOBMI-NEXT: retq
; ;
@ -646,38 +646,24 @@ define i1 @or_cmp_ne_i32(i32 %x, i32 %y) {
} }
define i1 @or_cmp_eq_i16(i16 zeroext %x, i16 zeroext %y) { define i1 @or_cmp_eq_i16(i16 zeroext %x, i16 zeroext %y) {
; NOBMI-LABEL: or_cmp_eq_i16: ; CHECK-LABEL: or_cmp_eq_i16:
; NOBMI: # %bb.0: ; CHECK: # %bb.0:
; NOBMI-NEXT: orl %edi, %esi ; CHECK-NEXT: notl %edi
; NOBMI-NEXT: cmpw %si, %di ; CHECK-NEXT: testw %si, %di
; NOBMI-NEXT: sete %al ; CHECK-NEXT: sete %al
; NOBMI-NEXT: retq ; CHECK-NEXT: retq
;
; BMI-LABEL: or_cmp_eq_i16:
; BMI: # %bb.0:
; BMI-NEXT: notl %edi
; BMI-NEXT: testw %si, %di
; BMI-NEXT: sete %al
; BMI-NEXT: retq
%o = or i16 %x, %y %o = or i16 %x, %y
%c = icmp eq i16 %x, %o %c = icmp eq i16 %x, %o
ret i1 %c ret i1 %c
} }
define i1 @or_cmp_ne_i8(i8 zeroext %x, i8 zeroext %y) { define i1 @or_cmp_ne_i8(i8 zeroext %x, i8 zeroext %y) {
; NOBMI-LABEL: or_cmp_ne_i8: ; CHECK-LABEL: or_cmp_ne_i8:
; NOBMI: # %bb.0: ; CHECK: # %bb.0:
; NOBMI-NEXT: orl %esi, %edi ; CHECK-NEXT: notb %sil
; NOBMI-NEXT: cmpb %dil, %sil ; CHECK-NEXT: testb %dil, %sil
; NOBMI-NEXT: setne %al ; CHECK-NEXT: setne %al
; NOBMI-NEXT: retq ; CHECK-NEXT: retq
;
; BMI-LABEL: or_cmp_ne_i8:
; BMI: # %bb.0:
; BMI-NEXT: notb %sil
; BMI-NEXT: testb %dil, %sil
; BMI-NEXT: setne %al
; BMI-NEXT: retq
%o = or i8 %x, %y %o = or i8 %x, %y
%c = icmp ne i8 %y, %o %c = icmp ne i8 %y, %o
ret i1 %c ret i1 %c

View File

@ -4,7 +4,6 @@
; CHECK-LABEL: test1 ; CHECK-LABEL: test1
; CHECK: orl $2 ; CHECK: orl $2
; CHECK-NEXT: cmpl $6 ; CHECK-NEXT: cmpl $6
define void @test1(i32 %variable) nounwind { define void @test1(i32 %variable) nounwind {
entry: entry:
switch i32 %variable, label %if.end [ switch i32 %variable, label %if.end [
@ -21,8 +20,7 @@ if.end:
} }
; CHECK-LABEL: test2 ; CHECK-LABEL: test2
; CHECK: orl $-2147483648 ; CHECK: testl $2147483647
; CHECK-NEXT: cmpl $-2147483648
define void @test2(i32 %variable) nounwind { define void @test2(i32 %variable) nounwind {
entry: entry:
switch i32 %variable, label %if.end [ switch i32 %variable, label %if.end [