llvm.org GIT mirror llvm / 4506e1d
[x86] add smin/smax with zero tests These are vector tests corresponding to the discussion at: http://lists.llvm.org/pipermail/llvm-dev/2016-November/106868.html Apart from the lack of min/max matching, the and/andn difference shows a lack of DAG-level canonicalization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286737 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
1 changed file(s) with 64 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3131 ret <4 x i32> %sel
3232 }
3333
34 ; Z = X -nsw Y
35 ; (X >s Y) ? 0 : Z ==> (Z >s 0) ? 0 : Z ==> SMIN(Z, 0)
36 define <4 x i32> @smin_vec3(<4 x i32> %x, <4 x i32> %y) {
37 ; CHECK-LABEL: smin_vec3:
38 ; CHECK: # BB#0:
39 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
40 ; CHECK-NEXT: vpcmpgtd %xmm1, %xmm0, %xmm0
41 ; CHECK-NEXT: vpandn %xmm2, %xmm0, %xmm0
42 ; CHECK-NEXT: retq
43 ;
44 %sub = sub nsw <4 x i32> %x, %y
45 %cmp = icmp sgt <4 x i32> %x, %y
46 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub
47 ret <4 x i32> %sel
48 }
49
50 ; Z = X -nsw Y
51 ; (X (Z SMIN(Z, 0)
52 define <4 x i32> @smin_vec4(<4 x i32> %x, <4 x i32> %y) {
53 ; CHECK-LABEL: smin_vec4:
54 ; CHECK: # BB#0:
55 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
56 ; CHECK-NEXT: vpcmpgtd %xmm0, %xmm1, %xmm0
57 ; CHECK-NEXT: vpand %xmm2, %xmm0, %xmm0
58 ; CHECK-NEXT: retq
59 ;
60 %sub = sub nsw <4 x i32> %x, %y
61 %cmp = icmp slt <4 x i32> %x, %y
62 %sel = select <4 x i1> %cmp, <4 x i32> %sub, <4 x i32> zeroinitializer
63 ret <4 x i32> %sel
64 }
65
3466 define <4 x i32> @smax_vec1(<4 x i32> %x) {
3567 ; CHECK-LABEL: smax_vec1:
3668 ; CHECK: # BB#0:
5688 %not_x = xor <4 x i32> %x,
5789 %cmp = icmp sgt <4 x i32> %x, zeroinitializer
5890 %sel = select <4 x i1> %cmp, <4 x i32> , <4 x i32> %not_x
91 ret <4 x i32> %sel
92 }
93
94 ; Z = X -nsw Y
95 ; (X (Z SMAX(Z, 0)
96 define <4 x i32> @smax_vec3(<4 x i32> %x, <4 x i32> %y) {
97 ; CHECK-LABEL: smax_vec3:
98 ; CHECK: # BB#0:
99 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
100 ; CHECK-NEXT: vpcmpgtd %xmm0, %xmm1, %xmm0
101 ; CHECK-NEXT: vpandn %xmm2, %xmm0, %xmm0
102 ; CHECK-NEXT: retq
103 ;
104 %sub = sub nsw <4 x i32> %x, %y
105 %cmp = icmp slt <4 x i32> %x, %y
106 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub
107 ret <4 x i32> %sel
108 }
109
110 ; Z = X -nsw Y
111 ; (X >s Y) ? Z : 0 ==> (Z >s 0) ? Z : 0 ==> SMAX(Z, 0)
112 define <4 x i32> @smax_vec4(<4 x i32> %x, <4 x i32> %y) {
113 ; CHECK-LABEL: smax_vec4:
114 ; CHECK: # BB#0:
115 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
116 ; CHECK-NEXT: vpcmpgtd %xmm1, %xmm0, %xmm0
117 ; CHECK-NEXT: vpand %xmm2, %xmm0, %xmm0
118 ; CHECK-NEXT: retq
119 ;
120 %sub = sub nsw <4 x i32> %x, %y
121 %cmp = icmp sgt <4 x i32> %x, %y
122 %sel = select <4 x i1> %cmp, <4 x i32> %sub, <4 x i32> zeroinitializer
59123 ret <4 x i32> %sel
60124 }
61125