blob: 3f8662d507eecd05f2e279958d3f90f52942acd8 [file] [log] [blame]
Tom Stellard49f8bfd2015-01-06 18:00:21 +00001; RUN: llc -march=amdgcn -mcpu=SI < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +00002
3declare i32 @llvm.r600.read.tidig.x() nounwind readnone
4
Matt Arsenaultfabab4b2015-12-11 23:16:47 +00005; FUNC-LABEL: {{^}}v_test_imax_sge_i32:
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +00006; SI: v_max_i32_e32
7define void @v_test_imax_sge_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr) nounwind {
8 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +00009 %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
10 %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
11 %outgep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +000012 %a = load i32, i32 addrspace(1)* %gep0, align 4
13 %b = load i32, i32 addrspace(1)* %gep1, align 4
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +000014 %cmp = icmp sge i32 %a, %b
15 %val = select i1 %cmp, i32 %a, i32 %b
16 store i32 %val, i32 addrspace(1)* %outgep, align 4
17 ret void
18}
19
Matt Arsenaultfabab4b2015-12-11 23:16:47 +000020; FUNC-LABEL: {{^}}v_test_imax_sge_v4i32:
21; SI: v_max_i32_e32
22; SI: v_max_i32_e32
23; SI: v_max_i32_e32
24; SI: v_max_i32_e32
25define void @v_test_imax_sge_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %aptr, <4 x i32> addrspace(1)* %bptr) nounwind {
26 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
27 %gep0 = getelementptr <4 x i32>, <4 x i32> addrspace(1)* %aptr, i32 %tid
28 %gep1 = getelementptr <4 x i32>, <4 x i32> addrspace(1)* %bptr, i32 %tid
29 %outgep = getelementptr <4 x i32>, <4 x i32> addrspace(1)* %out, i32 %tid
30 %a = load <4 x i32>, <4 x i32> addrspace(1)* %gep0, align 4
31 %b = load <4 x i32>, <4 x i32> addrspace(1)* %gep1, align 4
32 %cmp = icmp sge <4 x i32> %a, %b
33 %val = select <4 x i1> %cmp, <4 x i32> %a, <4 x i32> %b
34 store <4 x i32> %val, <4 x i32> addrspace(1)* %outgep, align 4
35 ret void
36}
37
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +000038; FUNC-LABEL: @s_test_imax_sge_i32
39; SI: s_max_i32
40define void @s_test_imax_sge_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
41 %cmp = icmp sge i32 %a, %b
42 %val = select i1 %cmp, i32 %a, i32 %b
43 store i32 %val, i32 addrspace(1)* %out, align 4
44 ret void
45}
46
Matt Arsenault314eac72015-03-13 16:43:48 +000047; FUNC-LABEL: {{^}}s_test_imax_sge_imm_i32:
48; SI: s_max_i32 {{s[0-9]+}}, {{s[0-9]+}}, 9
49define void @s_test_imax_sge_imm_i32(i32 addrspace(1)* %out, i32 %a) nounwind {
50 %cmp = icmp sge i32 %a, 9
51 %val = select i1 %cmp, i32 %a, i32 9
52 store i32 %val, i32 addrspace(1)* %out, align 4
53 ret void
54}
55
56; FUNC-LABEL: {{^}}s_test_imax_sgt_imm_i32:
57; SI: s_max_i32 {{s[0-9]+}}, {{s[0-9]+}}, 9
58define void @s_test_imax_sgt_imm_i32(i32 addrspace(1)* %out, i32 %a) nounwind {
59 %cmp = icmp sgt i32 %a, 9
60 %val = select i1 %cmp, i32 %a, i32 9
61 store i32 %val, i32 addrspace(1)* %out, align 4
62 ret void
63}
64
Matt Arsenaultfabab4b2015-12-11 23:16:47 +000065; FUNC-LABEL: {{^}}s_test_imax_sgt_imm_v2i32:
66; SI: s_max_i32 {{s[0-9]+}}, {{s[0-9]+}}, 9
67; SI: s_max_i32 {{s[0-9]+}}, {{s[0-9]+}}, 9
68define void @s_test_imax_sgt_imm_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a) nounwind {
69 %cmp = icmp sgt <2 x i32> %a, <i32 9, i32 9>
70 %val = select <2 x i1> %cmp, <2 x i32> %a, <2 x i32> <i32 9, i32 9>
71 store <2 x i32> %val, <2 x i32> addrspace(1)* %out, align 4
72 ret void
73}
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +000074; FUNC-LABEL: @v_test_imax_sgt_i32
75; SI: v_max_i32_e32
76define void @v_test_imax_sgt_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr) nounwind {
77 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +000078 %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
79 %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
80 %outgep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +000081 %a = load i32, i32 addrspace(1)* %gep0, align 4
82 %b = load i32, i32 addrspace(1)* %gep1, align 4
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +000083 %cmp = icmp sgt i32 %a, %b
84 %val = select i1 %cmp, i32 %a, i32 %b
85 store i32 %val, i32 addrspace(1)* %outgep, align 4
86 ret void
87}
88
89; FUNC-LABEL: @s_test_imax_sgt_i32
90; SI: s_max_i32
91define void @s_test_imax_sgt_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
92 %cmp = icmp sgt i32 %a, %b
93 %val = select i1 %cmp, i32 %a, i32 %b
94 store i32 %val, i32 addrspace(1)* %out, align 4
95 ret void
96}
97
98; FUNC-LABEL: @v_test_umax_uge_i32
99; SI: v_max_u32_e32
100define void @v_test_umax_uge_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr) nounwind {
101 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000102 %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
103 %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
104 %outgep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +0000105 %a = load i32, i32 addrspace(1)* %gep0, align 4
106 %b = load i32, i32 addrspace(1)* %gep1, align 4
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +0000107 %cmp = icmp uge i32 %a, %b
108 %val = select i1 %cmp, i32 %a, i32 %b
109 store i32 %val, i32 addrspace(1)* %outgep, align 4
110 ret void
111}
112
113; FUNC-LABEL: @s_test_umax_uge_i32
114; SI: s_max_u32
115define void @s_test_umax_uge_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
116 %cmp = icmp uge i32 %a, %b
117 %val = select i1 %cmp, i32 %a, i32 %b
118 store i32 %val, i32 addrspace(1)* %out, align 4
119 ret void
120}
121
Matt Arsenaultfabab4b2015-12-11 23:16:47 +0000122; FUNC-LABEL: {{^}}s_test_umax_uge_v3i32:
123; SI: s_max_u32
124; SI: s_max_u32
125; SI: s_max_u32
126; SI-NOT: s_max_u32
127; SI: s_endpgm
128define void @s_test_umax_uge_v3i32(<3 x i32> addrspace(1)* %out, <3 x i32> %a, <3 x i32> %b) nounwind {
129 %cmp = icmp uge <3 x i32> %a, %b
130 %val = select <3 x i1> %cmp, <3 x i32> %a, <3 x i32> %b
131 store <3 x i32> %val, <3 x i32> addrspace(1)* %out, align 4
132 ret void
133}
134
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +0000135; FUNC-LABEL: @v_test_umax_ugt_i32
136; SI: v_max_u32_e32
137define void @v_test_umax_ugt_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr) nounwind {
138 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000139 %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
140 %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
141 %outgep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +0000142 %a = load i32, i32 addrspace(1)* %gep0, align 4
143 %b = load i32, i32 addrspace(1)* %gep1, align 4
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +0000144 %cmp = icmp ugt i32 %a, %b
145 %val = select i1 %cmp, i32 %a, i32 %b
146 store i32 %val, i32 addrspace(1)* %outgep, align 4
147 ret void
148}
149
Matt Arsenaultfabab4b2015-12-11 23:16:47 +0000150; FUNC-LABEL: {{^}}s_test_umax_ugt_i32:
Matt Arsenaultd28a7fd2014-11-14 18:30:06 +0000151; SI: s_max_u32
152define void @s_test_umax_ugt_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
153 %cmp = icmp ugt i32 %a, %b
154 %val = select i1 %cmp, i32 %a, i32 %b
155 store i32 %val, i32 addrspace(1)* %out, align 4
156 ret void
157}
Matt Arsenault705eb8f2015-06-09 00:52:41 +0000158
Matt Arsenaultfabab4b2015-12-11 23:16:47 +0000159; FUNC-LABEL: {{^}}s_test_umax_ugt_imm_v2i32:
160; SI: s_max_u32 {{s[0-9]+}}, {{s[0-9]+}}, 15
161; SI: s_max_u32 {{s[0-9]+}}, {{s[0-9]+}}, 23
162define void @s_test_umax_ugt_imm_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a) nounwind {
163 %cmp = icmp ugt <2 x i32> %a, <i32 15, i32 23>
164 %val = select <2 x i1> %cmp, <2 x i32> %a, <2 x i32> <i32 15, i32 23>
165 store <2 x i32> %val, <2 x i32> addrspace(1)* %out, align 4
166 ret void
167}
168
Matt Arsenault705eb8f2015-06-09 00:52:41 +0000169; Make sure redundant and removed
170; FUNC-LABEL: {{^}}simplify_demanded_bits_test_umax_ugt_i16:
171; SI-DAG: s_load_dword [[A:s[0-9]+]], {{s\[[0-9]+:[0-9]+\]}}, 0xb
172; SI-DAG: s_load_dword [[B:s[0-9]+]], {{s\[[0-9]+:[0-9]+\]}}, 0xc
Matt Arsenaultfabab4b2015-12-11 23:16:47 +0000173; SI: s_max_u32 [[MAX:s[0-9]+]], [[A]], [[B]]
174; SI-NEXT: v_mov_b32_e32 [[VMAX:v[0-9]+]], [[MAX]]
175; SI-NEXT: buffer_store_dword [[VMAX]]
Matt Arsenault705eb8f2015-06-09 00:52:41 +0000176define void @simplify_demanded_bits_test_umax_ugt_i16(i32 addrspace(1)* %out, i16 zeroext %a, i16 zeroext %b) nounwind {
177 %a.ext = zext i16 %a to i32
178 %b.ext = zext i16 %b to i32
179 %cmp = icmp ugt i32 %a.ext, %b.ext
180 %val = select i1 %cmp, i32 %a.ext, i32 %b.ext
181 %mask = and i32 %val, 65535
182 store i32 %mask, i32 addrspace(1)* %out
183 ret void
184}
185
186; Make sure redundant sign_extend_inreg removed.
187
Matt Arsenaultfabab4b2015-12-11 23:16:47 +0000188; FUNC-LABEL: {{^}}simplify_demanded_bits_test_max_slt_i16:
Matt Arsenault705eb8f2015-06-09 00:52:41 +0000189; SI-DAG: s_load_dword [[A:s[0-9]+]], {{s\[[0-9]+:[0-9]+\]}}, 0xb
190; SI-DAG: s_load_dword [[B:s[0-9]+]], {{s\[[0-9]+:[0-9]+\]}}, 0xc
Matt Arsenaultfabab4b2015-12-11 23:16:47 +0000191; SI: s_max_i32 [[MAX:s[0-9]+]], [[A]], [[B]]
192; SI-NEXT: v_mov_b32_e32 [[VMAX:v[0-9]+]], [[MAX]]
193; SI-NEXT: buffer_store_dword [[VMAX]]
194define void @simplify_demanded_bits_test_max_slt_i16(i32 addrspace(1)* %out, i16 signext %a, i16 signext %b) nounwind {
Matt Arsenault705eb8f2015-06-09 00:52:41 +0000195 %a.ext = sext i16 %a to i32
196 %b.ext = sext i16 %b to i32
197 %cmp = icmp sgt i32 %a.ext, %b.ext
198 %val = select i1 %cmp, i32 %a.ext, i32 %b.ext
199 %shl = shl i32 %val, 16
200 %sextinreg = ashr i32 %shl, 16
201 store i32 %sextinreg, i32 addrspace(1)* %out
202 ret void
203}
204
Matt Arsenaultfabab4b2015-12-11 23:16:47 +0000205; FUNC-LABEL: {{^}}s_test_imax_sge_i16:
206; SI: s_max_i32
207define void @s_test_imax_sge_i16(i16 addrspace(1)* %out, i16 %a, i16 %b) nounwind {
Matt Arsenault705eb8f2015-06-09 00:52:41 +0000208 %cmp = icmp sge i16 %a, %b
209 %val = select i1 %cmp, i16 %a, i16 %b
210 store i16 %val, i16 addrspace(1)* %out
211 ret void
212}