1 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,SI %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,VI %s
3 ; RUN: llc -march=amdgcn -mcpu=gfx1100 < %s | FileCheck -check-prefix=GFX11 %s
5 ; Test that materialization constants that are the bit reversed of
6 ; inline immediates are replaced with bfrev of the inline immediate to
9 ; GCN-LABEL: {{^}}materialize_0_i32:
10 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], 0{{$}}
11 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
12 define amdgpu_kernel void @materialize_0_i32(ptr addrspace(1) %out) {
13 store i32 0, ptr addrspace(1) %out
17 ; GCN-LABEL: {{^}}materialize_0_i64:
18 ; GCN: v_mov_b32_e32 v[[LOK:[0-9]+]], 0{{$}}
19 ; GCN: v_mov_b32_e32 v[[HIK:[0-9]+]], v[[LOK]]{{$}}
20 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
21 define amdgpu_kernel void @materialize_0_i64(ptr addrspace(1) %out) {
22 store i64 0, ptr addrspace(1) %out
26 ; GCN-LABEL: {{^}}materialize_neg1_i32:
27 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], -1{{$}}
28 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
29 define amdgpu_kernel void @materialize_neg1_i32(ptr addrspace(1) %out) {
30 store i32 -1, ptr addrspace(1) %out
34 ; GCN-LABEL: {{^}}materialize_neg1_i64:
35 ; GCN: v_mov_b32_e32 v[[LOK:[0-9]+]], -1{{$}}
36 ; GCN: v_mov_b32_e32 v[[HIK:[0-9]+]], v[[LOK]]{{$}}
37 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
38 define amdgpu_kernel void @materialize_neg1_i64(ptr addrspace(1) %out) {
39 store i64 -1, ptr addrspace(1) %out
43 ; GCN-LABEL: {{^}}materialize_signbit_i32:
44 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], 1{{$}}
45 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
46 define amdgpu_kernel void @materialize_signbit_i32(ptr addrspace(1) %out) {
47 store i32 -2147483648, ptr addrspace(1) %out
51 ; GCN-LABEL: {{^}}materialize_signbit_i64:
52 ; GCN-DAG: v_mov_b32_e32 v[[LOK:[0-9]+]], 0{{$}}
53 ; GCN-DAG: v_bfrev_b32_e32 v[[HIK:[0-9]+]], 1{{$}}
54 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
55 define amdgpu_kernel void @materialize_signbit_i64(ptr addrspace(1) %out) {
56 store i64 -9223372036854775808, ptr addrspace(1) %out
60 ; GCN-LABEL: {{^}}materialize_rev_neg16_i32:
61 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], -16{{$}}
62 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
63 define amdgpu_kernel void @materialize_rev_neg16_i32(ptr addrspace(1) %out) {
64 store i32 268435455, ptr addrspace(1) %out
68 ; GCN-LABEL: {{^}}materialize_rev_neg16_i64:
69 ; GCN-DAG: v_mov_b32_e32 v[[LOK:[0-9]+]], -1{{$}}
70 ; GCN-DAG: v_bfrev_b32_e32 v[[HIK:[0-9]+]], -16{{$}}
71 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
72 define amdgpu_kernel void @materialize_rev_neg16_i64(ptr addrspace(1) %out) {
73 store i64 1152921504606846975, ptr addrspace(1) %out
77 ; GCN-LABEL: {{^}}materialize_rev_neg17_i32:
78 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], 0xf7ffffff{{$}}
79 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
80 define amdgpu_kernel void @materialize_rev_neg17_i32(ptr addrspace(1) %out) {
81 store i32 -134217729, ptr addrspace(1) %out
85 ; GCN-LABEL: {{^}}materialize_rev_neg17_i64:
86 ; GCN-DAG: v_mov_b32_e32 v[[LOK:[0-9]+]], -1{{$}}
87 ; GCN-DAG: v_mov_b32_e32 v[[HIK:[0-9]+]], 0xf7ffffff{{$}}
88 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
89 define amdgpu_kernel void @materialize_rev_neg17_i64(ptr addrspace(1) %out) {
90 store i64 -576460752303423489, ptr addrspace(1) %out
94 ; GCN-LABEL: {{^}}materialize_rev_64_i32:
95 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], 64{{$}}
96 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
97 define amdgpu_kernel void @materialize_rev_64_i32(ptr addrspace(1) %out) {
98 store i32 33554432, ptr addrspace(1) %out
102 ; GCN-LABEL: {{^}}materialize_rev_64_i64:
103 ; GCN-DAG: v_mov_b32_e32 v[[LOK:[0-9]+]], 0{{$}}
104 ; GCN-DAG: v_bfrev_b32_e32 v[[HIK:[0-9]+]], 64{{$}}
105 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
106 define amdgpu_kernel void @materialize_rev_64_i64(ptr addrspace(1) %out) {
107 store i64 144115188075855872, ptr addrspace(1) %out
111 ; GCN-LABEL: {{^}}materialize_rev_65_i32:
112 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], 0x82000000{{$}}
113 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
114 define amdgpu_kernel void @materialize_rev_65_i32(ptr addrspace(1) %out) {
115 store i32 -2113929216, ptr addrspace(1) %out
119 ; GCN-LABEL: {{^}}materialize_rev_65_i64:
120 ; GCN-DAG: v_mov_b32_e32 v[[LOK:[0-9]+]], 0{{$}}
121 ; GCN-DAG: v_mov_b32_e32 v[[HIK:[0-9]+]], 0x82000000{{$}}
122 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
123 define amdgpu_kernel void @materialize_rev_65_i64(ptr addrspace(1) %out) {
124 store i64 -9079256848778919936, ptr addrspace(1) %out
128 ; GCN-LABEL: {{^}}materialize_rev_3_i32:
129 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], -2.0{{$}}
130 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
131 define amdgpu_kernel void @materialize_rev_3_i32(ptr addrspace(1) %out) {
132 store i32 -1073741824, ptr addrspace(1) %out
136 ; GCN-LABEL: {{^}}materialize_rev_3_i64:
137 ; GCN-DAG: v_mov_b32_e32 v[[LOK:[0-9]+]], 0{{$}}
138 ; GCN-DAG: v_mov_b32_e32 v[[HIK:[0-9]+]], -2.0{{$}}
139 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
140 define amdgpu_kernel void @materialize_rev_3_i64(ptr addrspace(1) %out) {
141 store i64 -4611686018427387904, ptr addrspace(1) %out
145 ; GCN-LABEL: {{^}}materialize_rev_0.5_i32:
146 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], 0.5{{$}}
147 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
148 define amdgpu_kernel void @materialize_rev_0.5_i32(ptr addrspace(1) %out) {
149 store i32 252, ptr addrspace(1) %out
153 ; GCN-LABEL: {{^}}materialize_rev_1.0_i32:
154 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], 1.0{{$}}
155 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
156 define amdgpu_kernel void @materialize_rev_1.0_i32(ptr addrspace(1) %out) {
157 store i32 508, ptr addrspace(1) %out
161 ; GCN-LABEL: {{^}}materialize_rev_2.0_i32:
162 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], 2{{$}}
163 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
164 define amdgpu_kernel void @materialize_rev_2.0_i32(ptr addrspace(1) %out) {
165 store i32 2, ptr addrspace(1) %out
169 ; GCN-LABEL: {{^}}materialize_rev_4.0_i32:
170 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], 4.0{{$}}
171 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
172 define amdgpu_kernel void @materialize_rev_4.0_i32(ptr addrspace(1) %out) {
173 store i32 258, ptr addrspace(1) %out
177 ; GCN-LABEL: {{^}}materialize_rev_neg0.5_i32:
178 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], -0.5{{$}}
179 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
180 define amdgpu_kernel void @materialize_rev_neg0.5_i32(ptr addrspace(1) %out) {
181 store i32 253, ptr addrspace(1) %out
185 ; GCN-LABEL: {{^}}materialize_rev_neg1.0_i32:
186 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], -1.0{{$}}
187 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
188 define amdgpu_kernel void @materialize_rev_neg1.0_i32(ptr addrspace(1) %out) {
189 store i32 509, ptr addrspace(1) %out
193 ; GCN-LABEL: {{^}}materialize_rev_neg2.0_i32:
194 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], 3{{$}}
195 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
196 define amdgpu_kernel void @materialize_rev_neg2.0_i32(ptr addrspace(1) %out) {
197 store i32 3, ptr addrspace(1) %out
201 ; GCN-LABEL: {{^}}materialize_rev_neg4.0_i32:
202 ; GCN: v_bfrev_b32_e32 [[K:v[0-9]+]], -4.0{{$}}
203 ; GCN: {{buffer|flat}}_store_dword {{.*}}[[K]]
204 define amdgpu_kernel void @materialize_rev_neg4.0_i32(ptr addrspace(1) %out) {
205 store i32 259, ptr addrspace(1) %out
209 ; GCN-LABEL: {{^}}materialize_rev_1.0_i64:
210 ; GCN-DAG: v_bfrev_b32_e32 v[[LOK:[0-9]+]], 1.0{{$}}
211 ; GCN-DAG: v_mov_b32_e32 v[[HIK:[0-9]+]], 0{{$}}
212 ; GCN: {{buffer|flat}}_store_dwordx2 {{.*}}v[[[LOK]]:[[HIK]]]
213 define amdgpu_kernel void @materialize_rev_1.0_i64(ptr addrspace(1) %out) {
214 store i64 508, ptr addrspace(1) %out
218 ; GCN-LABEL: {{^}}s_materialize_0_i32:
219 ; GCN: s_mov_b32 s{{[0-9]+}}, 0{{$}}
220 define amdgpu_kernel void @s_materialize_0_i32() {
221 call void asm sideeffect "; use $0", "s"(i32 0)
225 ; GCN-LABEL: {{^}}s_materialize_1_i32:
226 ; GCN: s_mov_b32 s{{[0-9]+}}, 1{{$}}
227 define amdgpu_kernel void @s_materialize_1_i32() {
228 call void asm sideeffect "; use $0", "s"(i32 1)
232 ; GCN-LABEL: {{^}}s_materialize_neg1_i32:
233 ; GCN: s_mov_b32 s{{[0-9]+}}, -1{{$}}
234 define amdgpu_kernel void @s_materialize_neg1_i32() {
235 call void asm sideeffect "; use $0", "s"(i32 -1)
239 ; GCN-LABEL: {{^}}s_materialize_signbit_i32:
240 ; GCN: s_brev_b32 s{{[0-9]+}}, 1{{$}}
241 define amdgpu_kernel void @s_materialize_signbit_i32() {
242 call void asm sideeffect "; use $0", "s"(i32 -2147483648)
246 ; GCN-LABEL: {{^}}s_materialize_rev_64_i32:
247 ; GCN: s_brev_b32 s{{[0-9]+}}, 64{{$}}
248 define amdgpu_kernel void @s_materialize_rev_64_i32() {
249 call void asm sideeffect "; use $0", "s"(i32 33554432)
253 ; GCN-LABEL: {{^}}s_materialize_rev_65_i32:
254 ; GCN: s_mov_b32 s{{[0-9]+}}, 0x82000000{{$}}
255 define amdgpu_kernel void @s_materialize_rev_65_i32() {
256 call void asm sideeffect "; use $0", "s"(i32 -2113929216)
260 ; GCN-LABEL: {{^}}s_materialize_rev_neg16_i32:
261 ; GCN: s_brev_b32 s{{[0-9]+}}, -16{{$}}
262 define amdgpu_kernel void @s_materialize_rev_neg16_i32() {
263 call void asm sideeffect "; use $0", "s"(i32 268435455)
267 ; GCN-LABEL: {{^}}s_materialize_rev_neg17_i32:
268 ; GCN: s_mov_b32 s{{[0-9]+}}, 0xf7ffffff{{$}}
269 define amdgpu_kernel void @s_materialize_rev_neg17_i32() {
270 call void asm sideeffect "; use $0", "s"(i32 -134217729)
274 ; GCN-LABEL: {{^}}s_materialize_rev_1.0_i32:
275 ; GCN: s_movk_i32 s{{[0-9]+}}, 0x1fc{{$}}
276 define amdgpu_kernel void @s_materialize_rev_1.0_i32() {
277 call void asm sideeffect "; use $0", "s"(i32 508)
281 ; GCN-LABEL: {{^}}s_materialize_not_1.0_i32:
282 ; GCN: s_mov_b32 s{{[0-9]+}}, 0xc07fffff
283 define void @s_materialize_not_1.0_i32() {
284 call void asm sideeffect "; use $0", "s"(i32 -1065353217)
288 ; GCN-LABEL: {{^}}s_materialize_not_neg_1.0_i32:
289 ; GCN: s_mov_b32 s{{[0-9]+}}, 0x407fffff
290 define void @s_materialize_not_neg_1.0_i32() {
291 call void asm sideeffect "; use $0", "s"(i32 1082130431)
295 ; GCN-LABEL: {{^}}s_materialize_not_inv2pi_i32:
296 ; GCN: s_mov_b32 s{{[0-9]+}}, 0xc1dd067c
297 define void @s_materialize_not_inv2pi_i32() {
298 call void asm sideeffect "; use $0", "s"(i32 -1042479492)
302 ; GCN-LABEL: {{^}}s_materialize_not_neg_inv2pi_i32:
303 ; GCN: s_mov_b32 s{{[0-9]+}}, 0x41dd067c
304 define void @s_materialize_not_neg_inv2pi_i32() {
305 call void asm sideeffect "; use $0", "s"(i32 1105004156)
309 ; GCN-LABEL: {{^}}materialize_not_0.5_i32:
310 ; GCN: v_not_b32_e32 v{{[0-9]+}}, 0.5
311 define void @materialize_not_0.5_i32(ptr addrspace(1) %out) {
312 store i32 -1056964609, ptr addrspace(1) %out
316 ; GCN-LABEL: {{^}}materialize_not_1.0_i32:
317 ; GCN: v_not_b32_e32 v{{[0-9]+}}, 1.0
318 define void @materialize_not_1.0_i32(ptr addrspace(1) %out) {
319 store i32 -1065353217, ptr addrspace(1) %out
323 ; GCN-LABEL: {{^}}materialize_not_2.0_i32:
324 ; GCN: v_not_b32_e32 v{{[0-9]+}}, 2.0
325 define void @materialize_not_2.0_i32(ptr addrspace(1) %out) {
326 store i32 -1073741825, ptr addrspace(1) %out
330 ; GCN-LABEL: {{^}}materialize_not_4.0_i32:
331 ; GCN: v_not_b32_e32 v{{[0-9]+}}, 4.0
332 define void @materialize_not_4.0_i32(ptr addrspace(1) %out) {
333 store i32 -1082130433, ptr addrspace(1) %out
337 ; GCN-LABEL: {{^}}materialize_not_neg_0.5_i32:
338 ; GCN: v_not_b32_e32 v{{[0-9]+}}, -0.5
339 define void @materialize_not_neg_0.5_i32(ptr addrspace(1) %out) {
340 store i32 1090519039, ptr addrspace(1) %out
344 ; GCN-LABEL: {{^}}materialize_not_neg_1.0_i32:
345 ; GCN: v_not_b32_e32 v{{[0-9]+}}, -1.0
346 define void @materialize_not_neg_1.0_i32(ptr addrspace(1) %out) {
347 store i32 1082130431, ptr addrspace(1) %out
351 ; GCN-LABEL: {{^}}materialize_not_neg2.0_i32:
352 ; GCN: v_not_b32_e32 v{{[0-9]+}}, -2.0
353 define void @materialize_not_neg2.0_i32(ptr addrspace(1) %out) {
354 store i32 1073741823, ptr addrspace(1) %out
358 ; GCN-LABEL: {{^}}materialize_not_neg4.0_i32:
359 ; GCN: v_not_b32_e32 v{{[0-9]+}}, -4.0
360 define void @materialize_not_neg4.0_i32(ptr addrspace(1) %out) {
361 store i32 1065353215, ptr addrspace(1) %out
365 ; GCN-LABEL: {{^}}materialize_not_inv2pi_i32:
366 ; SI: v_mov_b32_e32 v{{[0-9]+}}, 0xc1dd067c
367 ; VI: v_not_b32_e32 v{{[0-9]+}}, 0.15915494
368 define void @materialize_not_inv2pi_i32(ptr addrspace(1) %out) {
369 store i32 -1042479492, ptr addrspace(1) %out
373 ; GCN-LABEL: {{^}}materialize_not_neg_inv2pi_i32:
374 ; GCN: v_mov_b32_e32 v{{[0-9]+}}, 0x41dd067c
375 define void @materialize_not_neg_inv2pi_i32(ptr addrspace(1) %out) {
376 store i32 1105004156, ptr addrspace(1) %out
380 ; One constant is reversible, the other is not. We shouldn't break
381 ; vopd packing for this.
382 ; GFX11-LABEL: {{^}}vopd_materialize:
383 ; FIXME-GFX11: v_dual_mov_b32 v0, 0x102 :: v_dual_mov_b32 v1, 1.0
384 ; GFX11: v_bfrev_b32_e32 v0, 4.0
385 ; GFX11: v_mov_b32_e32 v1, 1.0
386 define <2 x i32> @vopd_materialize() {
387 %insert0 = insertelement <2 x i32> poison, i32 258, i32 0
388 %insert1 = insertelement <2 x i32> %insert0, i32 1065353216, i32 1
389 ret <2 x i32> %insert1