forked from OSchip/llvm-project
[InstCombine] [NFC] Added tests for Select with binop fold
llvm-svn: 338257
This commit is contained in:
parent
24ec072e18
commit
403826ee0f
|
@ -1,6 +1,8 @@
|
|||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -instcombine -S | FileCheck %s
|
||||
|
||||
declare void @use(<2 x i1>)
|
||||
|
||||
define i32 @select_xor_icmp(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
|
||||
|
@ -14,6 +16,32 @@ define i32 @select_xor_icmp(i32 %x, i32 %y, i32 %z) {
|
|||
ret i32 %C
|
||||
}
|
||||
|
||||
define i32 @select_xor_icmp2(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp2(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
|
||||
; CHECK-NEXT: [[B:%.*]] = xor i32 [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
|
||||
; CHECK-NEXT: ret i32 [[C]]
|
||||
;
|
||||
%A = icmp ne i32 %x, 0
|
||||
%B = xor i32 %x, %z
|
||||
%C = select i1 %A, i32 %y, i32 %B
|
||||
ret i32 %C
|
||||
}
|
||||
|
||||
define i32 @select_xor_icmp_meta(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp_meta(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
|
||||
; CHECK-NEXT: [[B:%.*]] = xor i32 [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]], !prof !0
|
||||
; CHECK-NEXT: ret i32 [[C]]
|
||||
;
|
||||
%A = icmp eq i32 %x, 0
|
||||
%B = xor i32 %x, %z
|
||||
%C = select i1 %A, i32 %B, i32 %y, !prof !0
|
||||
ret i32 %C
|
||||
}
|
||||
|
||||
define i32 @select_mul_icmp(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-LABEL: @select_mul_icmp(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 1
|
||||
|
@ -79,16 +107,18 @@ define <2 x i8> @select_xor_icmp_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
|
|||
ret <2 x i8> %C
|
||||
}
|
||||
|
||||
define <2 x i8> @select_xor_icmp_vec2(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp_vec2(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 0, i8 undef>
|
||||
define <2 x i8> @select_xor_icmp_vec_use(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp_vec_use(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp ne <2 x i8> [[X:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: call void @use(<2 x i1> [[A]])
|
||||
; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select <2 x i1> [[A]], <2 x i8> [[B]], <2 x i8> [[Y:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select <2 x i1> [[A]], <2 x i8> [[Y:%.*]], <2 x i8> [[B]]
|
||||
; CHECK-NEXT: ret <2 x i8> [[C]]
|
||||
;
|
||||
%A = icmp eq <2 x i8> %x, <i8 0, i8 undef>
|
||||
%A = icmp ne <2 x i8> %x, <i8 0, i8 0>
|
||||
call void @use(<2 x i1> %A)
|
||||
%B = xor <2 x i8> %x, %z
|
||||
%C = select <2 x i1> %A, <2 x i8> %B, <2 x i8> %y
|
||||
%C = select <2 x i1> %A, <2 x i8> %y, <2 x i8> %B
|
||||
ret <2 x i8> %C
|
||||
}
|
||||
|
||||
|
@ -105,6 +135,19 @@ define i32 @select_xor_inv_icmp(i32 %x, i32 %y, i32 %z) {
|
|||
ret i32 %C
|
||||
}
|
||||
|
||||
define i32 @select_xor_inv_icmp2(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-LABEL: @select_xor_inv_icmp2(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
|
||||
; CHECK-NEXT: [[B:%.*]] = xor i32 [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
|
||||
; CHECK-NEXT: ret i32 [[C]]
|
||||
;
|
||||
%A = icmp ne i32 %x, 0
|
||||
%B = xor i32 %x, %z
|
||||
%C = select i1 %A, i32 %y, i32 %B
|
||||
ret i32 %C
|
||||
}
|
||||
|
||||
; Negative tests
|
||||
define i32 @select_xor_icmp_bad_1(i32 %x, i32 %y, i32 %z, i32 %k) {
|
||||
; CHECK-LABEL: @select_xor_icmp_bad_1(
|
||||
|
@ -171,6 +214,19 @@ define i32 @select_xor_icmp_bad_5(i32 %x, i32 %y, i32 %z) {
|
|||
ret i32 %C
|
||||
}
|
||||
|
||||
define i32 @select_xor_icmp_bad_6(i32 %x, i32 %y, i32 %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp_bad_6(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 1
|
||||
; CHECK-NEXT: [[B:%.*]] = xor i32 [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
|
||||
; CHECK-NEXT: ret i32 [[C]]
|
||||
;
|
||||
%A = icmp ne i32 %x, 1
|
||||
%B = xor i32 %x, %z
|
||||
%C = select i1 %A, i32 %y, i32 %B
|
||||
ret i32 %C
|
||||
}
|
||||
|
||||
define <2 x i8> @select_xor_icmp_vec_bad(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp_vec_bad(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 5, i8 3>
|
||||
|
@ -184,6 +240,19 @@ define <2 x i8> @select_xor_icmp_vec_bad(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z)
|
|||
ret <2 x i8> %C
|
||||
}
|
||||
|
||||
define <2 x i8> @select_xor_icmp_vec_bad_2(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
|
||||
; CHECK-LABEL: @select_xor_icmp_vec_bad_2(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 0, i8 undef>
|
||||
; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> [[X]], [[Z:%.*]]
|
||||
; CHECK-NEXT: [[C:%.*]] = select <2 x i1> [[A]], <2 x i8> [[B]], <2 x i8> [[Y:%.*]]
|
||||
; CHECK-NEXT: ret <2 x i8> [[C]]
|
||||
;
|
||||
%A = icmp eq <2 x i8> %x, <i8 0, i8 undef>
|
||||
%B = xor <2 x i8> %x, %z
|
||||
%C = select <2 x i1> %A, <2 x i8> %B, <2 x i8> %y
|
||||
ret <2 x i8> %C
|
||||
}
|
||||
|
||||
define i32 @select_mul_icmp_bad(i32 %x, i32 %y, i32 %z, i32 %k) {
|
||||
; CHECK-LABEL: @select_mul_icmp_bad(
|
||||
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 3
|
||||
|
@ -328,3 +397,5 @@ define float @select_fmul_icmp(float %x, float %y, float %z) {
|
|||
%C = select i1 %A, float %B, float %y
|
||||
ret float %C
|
||||
}
|
||||
|
||||
!0 = !{!"branch_weights", i32 2, i32 10}
|
||||
|
|
Loading…
Reference in New Issue