1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

[InstCombine] auto-generate better checks; NFC

Note that the existing metadata checking was re-added by hand because the 
script doesn't currently know how to generate checks for lines outside of 
functions.

llvm-svn: 286460
This commit is contained in:
Sanjay Patel 2016-11-10 14:58:17 +00:00
parent 502e3f027d
commit d261791644

View File

@ -1,16 +1,31 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py and enhanced to include metadata checking.
; RUN: opt < %s -instcombine -S | FileCheck %s ; RUN: opt < %s -instcombine -S | FileCheck %s
define i32 @foo(i32) local_unnamed_addr #0 { define i32 @foo(i32) local_unnamed_addr #0 {
; CHECK-LABEL: @foo(
; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 %0, 2
; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[TMP2]], i32 20, i32 -20, !prof ![[MD1:[0-9]+]]
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[DOTV]], %0
; CHECK-NEXT: ret i32 [[TMP3]]
;
%2 = icmp sgt i32 %0, 2 %2 = icmp sgt i32 %0, 2
%3 = add nsw i32 %0, 20 %3 = add nsw i32 %0, 20
%4 = add nsw i32 %0, -20 %4 = add nsw i32 %0, -20
select i1 %2, i32 %3, i32 %4, !prof !1 select i1 %2, i32 %3, i32 %4, !prof !1
ret i32 %5 ret i32 %5
; CHECK-LABEL: @foo
; CHECK: select i1 %2, {{.*}} !prof ![[MD1:[0-9]+]]
} }
define void @min_max_bitcast(<4 x float> %a, <4 x float> %b, <4 x i32>* %ptr1, <4 x i32>* %ptr2) { define void @min_max_bitcast(<4 x float> %a, <4 x float> %b, <4 x i32>* %ptr1, <4 x i32>* %ptr2) {
; CHECK-LABEL: @min_max_bitcast(
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <4 x float> %a, %b
; CHECK-NEXT: [[SEL1_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> %a, <4 x float> %b, !prof ![[MD1]]
; CHECK-NEXT: [[SEL2_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> %b, <4 x float> %a, !prof ![[MD1]]
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32>* %ptr1 to <4 x float>*
; CHECK-NEXT: store <4 x float> [[SEL1_V]], <4 x float>* [[TMP1]], align 16
; CHECK-NEXT: [[TMP2:%.*]] = bitcast <4 x i32>* %ptr2 to <4 x float>*
; CHECK-NEXT: store <4 x float> [[SEL2_V]], <4 x float>* [[TMP2]], align 16
; CHECK-NEXT: ret void
;
%cmp = fcmp olt <4 x float> %a, %b %cmp = fcmp olt <4 x float> %a, %b
%bc1 = bitcast <4 x float> %a to <4 x i32> %bc1 = bitcast <4 x float> %a to <4 x i32>
%bc2 = bitcast <4 x float> %b to <4 x i32> %bc2 = bitcast <4 x float> %b to <4 x i32>
@ -19,54 +34,69 @@ define void @min_max_bitcast(<4 x float> %a, <4 x float> %b, <4 x i32>* %ptr1, <
store <4 x i32> %sel1, <4 x i32>* %ptr1 store <4 x i32> %sel1, <4 x i32>* %ptr1
store <4 x i32> %sel2, <4 x i32>* %ptr2 store <4 x i32> %sel2, <4 x i32>* %ptr2
ret void ret void
; CHECK-LABEL: @min_max_bitcast
; CHECK: select {{.*}} %cmp,{{.*}}!prof ![[MD1]]
} }
define i32 @foo2(i32, i32) local_unnamed_addr #0 { define i32 @foo2(i32, i32) local_unnamed_addr #0 {
; CHECK-LABEL: @foo2(
; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i32 %0, 2
; CHECK-NEXT: [[TMP4:%.*]] = sub i32 0, %1
; CHECK-NEXT: [[DOTP:%.*]] = select i1 [[TMP3]], i32 %1, i32 [[TMP4]], !prof ![[MD1]]
; CHECK-NEXT: [[TMP5:%.*]] = add i32 [[DOTP]], %0
; CHECK-NEXT: ret i32 [[TMP5]]
;
%3 = icmp sgt i32 %0, 2 %3 = icmp sgt i32 %0, 2
%4 = add nsw i32 %0, %1 %4 = add nsw i32 %0, %1
%5 = sub nsw i32 %0, %1 %5 = sub nsw i32 %0, %1
select i1 %3, i32 %4, i32 %5, !prof !1 select i1 %3, i32 %4, i32 %5, !prof !1
ret i32 %6 ret i32 %6
; CHECK-LABEL: @foo2
; CHECK: select i1 %3, {{.*}}, !prof ![[MD1]]
} }
; condition swapped ; condition swapped
define i64 @test43(i32 %a) nounwind { define i64 @test43(i32 %a) nounwind {
; CHECK-LABEL: @test43(
; CHECK-NEXT: [[A_EXT:%.*]] = sext i32 %a to i64
; CHECK-NEXT: [[IS_A_NONNEGATIVE:%.*]] = icmp slt i64 [[A_EXT]], 0
; CHECK-NEXT: [[MAX:%.*]] = select i1 [[IS_A_NONNEGATIVE]], i64 0, i64 [[A_EXT]], !prof ![[MD3:[0-9]+]]
; CHECK-NEXT: ret i64 [[MAX]]
;
%a_ext = sext i32 %a to i64 %a_ext = sext i32 %a to i64
%is_a_nonnegative = icmp sgt i32 %a, -1 %is_a_nonnegative = icmp sgt i32 %a, -1
%max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0, !prof !1 %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0, !prof !1
ret i64 %max ret i64 %max
; CHECK-LABEL: @test43
; CHECK: select {{.*}}, i64 0, i64 %a_ext, !prof ![[MD3:[0-9]+]]
} }
define <2 x i32> @scalar_select_of_vectors_sext(<2 x i1> %cca, i1 %ccb) { define <2 x i32> @scalar_select_of_vectors_sext(<2 x i1> %cca, i1 %ccb) {
; CHECK-LABEL: @scalar_select_of_vectors_sext(
; CHECK-NEXT: [[NARROW:%.*]] = select i1 %ccb, <2 x i1> %cca, <2 x i1> zeroinitializer, !prof ![[MD1]]
; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[NARROW]] to <2 x i32>
; CHECK-NEXT: ret <2 x i32> [[R]]
;
%ccax = sext <2 x i1> %cca to <2 x i32> %ccax = sext <2 x i1> %cca to <2 x i32>
%r = select i1 %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 0>, !prof !1 %r = select i1 %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 0>, !prof !1
ret <2 x i32> %r ret <2 x i32> %r
; CHECK-LABEL: @scalar_select_of_vectors_sext(
; CHECK-NEXT: [[FOLD_R:%.*]] = select i1 %ccb, {{.*}}, !prof ![[MD1]]
; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[FOLD_R]] to <2 x i32>
; CHECK-NEXT: ret <2 x i32> [[R]]
} }
define i16 @t7(i32 %a) { define i16 @t7(i32 %a) {
; CHECK-LABEL: @t7(
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 %a, -32768
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 %a, i32 -32768, !prof ![[MD1]]
; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i16
; CHECK-NEXT: ret i16 [[TMP3]]
;
%1 = icmp slt i32 %a, -32768 %1 = icmp slt i32 %a, -32768
%2 = trunc i32 %a to i16 %2 = trunc i32 %a to i16
%3 = select i1 %1, i16 %2, i16 -32768, !prof !1 %3 = select i1 %1, i16 %2, i16 -32768, !prof !1
ret i16 %3 ret i16 %3
} }
; CHECK-LABEL: @t7
; CHECK-NEXT: icmp
; CHECK-NEXT: select i1 %1{{.*}}, !prof ![[MD1]]
; CHECK-NEXT: trunc
define i32 @abs_nabs_x01(i32 %x) { define i32 @abs_nabs_x01(i32 %x) {
; CHECK-LABEL: @abs_nabs_x01(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %x, -1
; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, %x
; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 %x, i32 [[SUB]], !prof ![[MD1]]
; CHECK-NEXT: ret i32 [[COND1]]
;
%cmp = icmp sgt i32 %x, -1 %cmp = icmp sgt i32 %x, -1
%sub = sub nsw i32 0, %x %sub = sub nsw i32 0, %x
%cond = select i1 %cmp, i32 %sub, i32 %x, !prof !1 %cond = select i1 %cmp, i32 %sub, i32 %x, !prof !1
@ -74,10 +104,6 @@ define i32 @abs_nabs_x01(i32 %x) {
%sub16 = sub nsw i32 0, %cond %sub16 = sub nsw i32 0, %cond
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16, !prof !2 %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16, !prof !2
ret i32 %cond18 ret i32 %cond18
; CHECK-LABEL: @abs_nabs_x01(
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]], !prof ![[MD1]]
} }
define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) { define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) {
@ -98,47 +124,58 @@ define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) {
; SMAX(SMAX(x, y), x) -> SMAX(x, y) ; SMAX(SMAX(x, y), x) -> SMAX(x, y)
define i32 @test30(i32 %x, i32 %y) { define i32 @test30(i32 %x, i32 %y) {
; CHECK-LABEL: @test30(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %x, %y
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 %x, i32 %y, !prof ![[MD1]]
; CHECK-NEXT: ret i32 [[COND]]
;
%cmp = icmp sgt i32 %x, %y %cmp = icmp sgt i32 %x, %y
%cond = select i1 %cmp, i32 %x, i32 %y, !prof !1 %cond = select i1 %cmp, i32 %x, i32 %y, !prof !1
%cmp5 = icmp sgt i32 %cond, %x %cmp5 = icmp sgt i32 %cond, %x
%retval = select i1 %cmp5, i32 %cond, i32 %x, !prof !2 %retval = select i1 %cmp5, i32 %cond, i32 %x, !prof !2
ret i32 %retval ret i32 %retval
; CHECK-LABEL: @test30
; CHECK: select {{.*}}, !prof ![[MD1]]
} }
define i32 @test70(i32 %x) { define i32 @test70(i32 %x) {
entry: ; CHECK-LABEL: @test70(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 %x, 75
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 75, i32 %x, !prof ![[MD1]]
; CHECK-NEXT: ret i32 [[COND]]
;
%cmp = icmp slt i32 %x, 75 %cmp = icmp slt i32 %x, 75
%cond = select i1 %cmp, i32 75, i32 %x, !prof !1 %cond = select i1 %cmp, i32 75, i32 %x, !prof !1
%cmp3 = icmp slt i32 %cond, 36 %cmp3 = icmp slt i32 %cond, 36
%retval = select i1 %cmp3, i32 36, i32 %cond, !prof !2 %retval = select i1 %cmp3, i32 36, i32 %cond, !prof !2
ret i32 %retval ret i32 %retval
; CHECK-LABEL: @test70
; CHECK: select {{.*}}, !prof ![[MD1]]
} }
; SMIN(SMIN(X, 92), 11) -> SMIN(X, 11) ; SMIN(SMIN(X, 92), 11) -> SMIN(X, 11)
define i32 @test72(i32 %x) { define i32 @test72(i32 %x) {
; CHECK-LABEL: @test72(
; CHECK-NEXT: [[CMP31:%.*]] = icmp sgt i32 %x, 11
; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[CMP31]], i32 11, i32 %x, !prof ![[MD2:[0-9]+]]
; CHECK-NEXT: ret i32 [[RETVAL]]
;
%cmp = icmp sgt i32 %x, 92 %cmp = icmp sgt i32 %x, 92
%cond = select i1 %cmp, i32 92, i32 %x, !prof !1 %cond = select i1 %cmp, i32 92, i32 %x, !prof !1
%cmp3 = icmp sgt i32 %cond, 11 %cmp3 = icmp sgt i32 %cond, 11
%retval = select i1 %cmp3, i32 11, i32 %cond, !prof !2 %retval = select i1 %cmp3, i32 11, i32 %cond, !prof !2
ret i32 %retval ret i32 %retval
; CHECK-LABEL: @test72
; CHECK: select {{.*}}, !prof ![[MD2:[0-9]+]]
} }
; SMAX(SMAX(X, 36), 75) -> SMAX(X, 75) ; SMAX(SMAX(X, 36), 75) -> SMAX(X, 75)
define i32 @test74(i32 %x) { define i32 @test74(i32 %x) {
; CHECK-LABEL: @test74(
; CHECK-NEXT: [[CMP31:%.*]] = icmp slt i32 %x, 75
; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[CMP31]], i32 75, i32 %x, !prof ![[MD2]]
; CHECK-NEXT: ret i32 [[RETVAL]]
;
%cmp = icmp slt i32 %x, 36 %cmp = icmp slt i32 %x, 36
%cond = select i1 %cmp, i32 36, i32 %x, !prof !1 %cond = select i1 %cmp, i32 36, i32 %x, !prof !1
%cmp3 = icmp slt i32 %cond, 75 %cmp3 = icmp slt i32 %cond, 75
%retval = select i1 %cmp3, i32 75, i32 %cond, !prof !2 %retval = select i1 %cmp3, i32 75, i32 %cond, !prof !2
ret i32 %retval ret i32 %retval
; CHECK-LABEL: @test74
; CHECK: select {{.*}}, !prof ![[MD2]]
} }
!1 = !{!"branch_weights", i32 2, i32 10} !1 = !{!"branch_weights", i32 2, i32 10}