1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 13:02:52 +02:00

[CodeGen][X86][NFC] Copy two selectcc tests from AArch64.

These tests are for DAGCombiner::foldSelectCCToShiftAnd().
Right now, they were only tested for AArch64,
but given the upcoming X86 changes to the hasAndNot(),
the test coverage needs to be added.

These tests originated from D27489 / rL289738

llvm-svn: 331454
This commit is contained in:
Roman Lebedev 2018-05-03 13:33:07 +00:00
parent c4c90c5eac
commit 8cf123ed80
2 changed files with 227 additions and 0 deletions

View File

@ -0,0 +1,27 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefix=CHECK-NOBMI
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefix=CHECK-BMI
; Optimize (x > -1) to (x >= 0) etc.
; Optimize (cmp (add / sub), 0): eliminate the subs used to update flag
; for comparison only
; rdar://10233472
define i32 @t1(i64 %a) {
; CHECK-NOBMI-LABEL: t1:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: testq %rdi, %rdi
; CHECK-NOBMI-NEXT: setns %al
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: t1:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: shrq $63, %rdi
; CHECK-BMI-NEXT: xorl $1, %edi
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: retq
%cmp = icmp sgt i64 %a, -1
%conv = zext i1 %cmp to i32
ret i32 %conv
}

View File

@ -0,0 +1,200 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefix=CHECK-NOBMI
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefix=CHECK-BMI
; Compare if negative and select of constants where one constant is zero.
define i32 @neg_sel_constants(i32 %a) {
; CHECK-NOBMI-LABEL: neg_sel_constants:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: sarl $31, %edi
; CHECK-NOBMI-NEXT: andl $5, %edi
; CHECK-NOBMI-NEXT: movl %edi, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: neg_sel_constants:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: sarl $31, %edi
; CHECK-BMI-NEXT: andl $5, %edi
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: retq
%tmp.1 = icmp slt i32 %a, 0
%retval = select i1 %tmp.1, i32 5, i32 0
ret i32 %retval
}
; Compare if negative and select of constants where one constant is zero and the other is a single bit.
define i32 @neg_sel_special_constant(i32 %a) {
; CHECK-NOBMI-LABEL: neg_sel_special_constant:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: shrl $22, %edi
; CHECK-NOBMI-NEXT: andl $512, %edi # imm = 0x200
; CHECK-NOBMI-NEXT: movl %edi, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: neg_sel_special_constant:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: shrl $22, %edi
; CHECK-BMI-NEXT: andl $512, %edi # imm = 0x200
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: retq
%tmp.1 = icmp slt i32 %a, 0
%retval = select i1 %tmp.1, i32 512, i32 0
ret i32 %retval
}
; Compare if negative and select variable or zero.
define i32 @neg_sel_variable_and_zero(i32 %a, i32 %b) {
; CHECK-NOBMI-LABEL: neg_sel_variable_and_zero:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: sarl $31, %edi
; CHECK-NOBMI-NEXT: andl %esi, %edi
; CHECK-NOBMI-NEXT: movl %edi, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: neg_sel_variable_and_zero:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: sarl $31, %edi
; CHECK-BMI-NEXT: andl %esi, %edi
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: retq
%tmp.1 = icmp slt i32 %a, 0
%retval = select i1 %tmp.1, i32 %b, i32 0
ret i32 %retval
}
; Compare if not positive and select the same variable as being compared: smin(a, 0).
define i32 @not_pos_sel_same_variable(i32 %a) {
; CHECK-NOBMI-LABEL: not_pos_sel_same_variable:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: movl %edi, %eax
; CHECK-NOBMI-NEXT: sarl $31, %eax
; CHECK-NOBMI-NEXT: andl %edi, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: not_pos_sel_same_variable:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: sarl $31, %eax
; CHECK-BMI-NEXT: andl %edi, %eax
; CHECK-BMI-NEXT: retq
%tmp = icmp slt i32 %a, 1
%min = select i1 %tmp, i32 %a, i32 0
ret i32 %min
}
; Flipping the comparison condition can be handled by getting the bitwise not of the sign mask.
; Compare if positive and select of constants where one constant is zero.
define i32 @pos_sel_constants(i32 %a) {
; CHECK-NOBMI-LABEL: pos_sel_constants:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: testl %edi, %edi
; CHECK-NOBMI-NEXT: setns %al
; CHECK-NOBMI-NEXT: leal (%rax,%rax,4), %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: pos_sel_constants:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: sarl $31, %edi
; CHECK-BMI-NEXT: notl %edi
; CHECK-BMI-NEXT: andl $5, %edi
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: retq
%tmp.1 = icmp sgt i32 %a, -1
%retval = select i1 %tmp.1, i32 5, i32 0
ret i32 %retval
}
; Compare if positive and select of constants where one constant is zero and the other is a single bit.
define i32 @pos_sel_special_constant(i32 %a) {
; CHECK-NOBMI-LABEL: pos_sel_special_constant:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: testl %edi, %edi
; CHECK-NOBMI-NEXT: setns %al
; CHECK-NOBMI-NEXT: shll $9, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: pos_sel_special_constant:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: shrl $22, %edi
; CHECK-BMI-NEXT: notl %edi
; CHECK-BMI-NEXT: andl $512, %edi # imm = 0x200
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: retq
%tmp.1 = icmp sgt i32 %a, -1
%retval = select i1 %tmp.1, i32 512, i32 0
ret i32 %retval
}
; Compare if positive and select variable or zero.
define i32 @pos_sel_variable_and_zero(i32 %a, i32 %b) {
; CHECK-NOBMI-LABEL: pos_sel_variable_and_zero:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: testl %edi, %edi
; CHECK-NOBMI-NEXT: cmovnsl %esi, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: pos_sel_variable_and_zero:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: sarl $31, %edi
; CHECK-BMI-NEXT: andnl %esi, %edi, %eax
; CHECK-BMI-NEXT: retq
%tmp.1 = icmp sgt i32 %a, -1
%retval = select i1 %tmp.1, i32 %b, i32 0
ret i32 %retval
}
; Compare if not negative or zero and select the same variable as being compared: smax(a, 0).
define i32 @not_neg_sel_same_variable(i32 %a) {
; CHECK-NOBMI-LABEL: not_neg_sel_same_variable:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: testl %edi, %edi
; CHECK-NOBMI-NEXT: cmovnsl %edi, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: not_neg_sel_same_variable:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: sarl $31, %eax
; CHECK-BMI-NEXT: andnl %edi, %eax, %eax
; CHECK-BMI-NEXT: retq
%tmp = icmp sgt i32 %a, 0
%min = select i1 %tmp, i32 %a, i32 0
ret i32 %min
}
; https://llvm.org/bugs/show_bug.cgi?id=31175
; ret = (x-y) > 0 ? x-y : 0
define i32 @PR31175(i32 %x, i32 %y) {
; CHECK-NOBMI-LABEL: PR31175:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: subl %esi, %edi
; CHECK-NOBMI-NEXT: cmovnsl %edi, %eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: PR31175:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: subl %esi, %edi
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: sarl $31, %eax
; CHECK-BMI-NEXT: andnl %edi, %eax, %eax
; CHECK-BMI-NEXT: retq
%sub = sub nsw i32 %x, %y
%cmp = icmp sgt i32 %sub, 0
%sel = select i1 %cmp, i32 %sub, i32 0
ret i32 %sel
}