1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=hawaii -mattr=-unaligned-access-mode < %s | FileCheck -check-prefixes=GCN,GFX7-ALIGNED %s
3; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=hawaii -mattr=+unaligned-access-mode < %s | FileCheck -check-prefixes=GCN,GFX7-UNALIGNED %s
4; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -mattr=+unaligned-access-mode < %s | FileCheck -check-prefixes=GCN,GFX9 %s
5
6; Should not merge this to a dword load
7define i32 @global_load_2xi16_align2(i16 addrspace(1)* %p) #0 {
8; GFX7-ALIGNED-LABEL: global_load_2xi16_align2:
9; GFX7-ALIGNED:       ; %bb.0:
10; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
11; GFX7-ALIGNED-NEXT:    v_add_i32_e32 v2, vcc, 2, v0
12; GFX7-ALIGNED-NEXT:    v_addc_u32_e32 v3, vcc, 0, v1, vcc
13; GFX7-ALIGNED-NEXT:    flat_load_ushort v0, v[0:1]
14; GFX7-ALIGNED-NEXT:    flat_load_ushort v1, v[2:3]
15; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(0)
16; GFX7-ALIGNED-NEXT:    v_lshlrev_b32_e32 v1, 16, v1
17; GFX7-ALIGNED-NEXT:    v_or_b32_e32 v0, v0, v1
18; GFX7-ALIGNED-NEXT:    s_setpc_b64 s[30:31]
19;
20; GFX7-UNALIGNED-LABEL: global_load_2xi16_align2:
21; GFX7-UNALIGNED:       ; %bb.0:
22; GFX7-UNALIGNED-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
23; GFX7-UNALIGNED-NEXT:    v_add_i32_e32 v2, vcc, 2, v0
24; GFX7-UNALIGNED-NEXT:    v_addc_u32_e32 v3, vcc, 0, v1, vcc
25; GFX7-UNALIGNED-NEXT:    flat_load_ushort v0, v[0:1]
26; GFX7-UNALIGNED-NEXT:    flat_load_ushort v1, v[2:3]
27; GFX7-UNALIGNED-NEXT:    s_waitcnt vmcnt(0)
28; GFX7-UNALIGNED-NEXT:    v_lshlrev_b32_e32 v1, 16, v1
29; GFX7-UNALIGNED-NEXT:    v_or_b32_e32 v0, v0, v1
30; GFX7-UNALIGNED-NEXT:    s_setpc_b64 s[30:31]
31;
32; GFX9-LABEL: global_load_2xi16_align2:
33; GFX9:       ; %bb.0:
34; GFX9-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
35; GFX9-NEXT:    global_load_ushort v2, v[0:1], off
36; GFX9-NEXT:    global_load_ushort v0, v[0:1], off offset:2
37; GFX9-NEXT:    s_waitcnt vmcnt(0)
38; GFX9-NEXT:    v_lshl_or_b32 v0, v0, 16, v2
39; GFX9-NEXT:    s_setpc_b64 s[30:31]
40  %gep.p = getelementptr i16, i16 addrspace(1)* %p, i64 1
41  %p.0 = load i16, i16 addrspace(1)* %p, align 2
42  %p.1 = load i16, i16 addrspace(1)* %gep.p, align 2
43  %zext.0 = zext i16 %p.0 to i32
44  %zext.1 = zext i16 %p.1 to i32
45  %shl.1 = shl i32 %zext.1, 16
46  %or = or i32 %zext.0, %shl.1
47  ret i32 %or
48}
49
50; Should not merge this to a dword store
51define amdgpu_kernel void @global_store_2xi16_align2(i16 addrspace(1)* %p, i16 addrspace(1)* %r) #0 {
52; GFX7-ALIGNED-LABEL: global_store_2xi16_align2:
53; GFX7-ALIGNED:       ; %bb.0:
54; GFX7-ALIGNED-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
55; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v2, 1
56; GFX7-ALIGNED-NEXT:    s_waitcnt lgkmcnt(0)
57; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v0, s0
58; GFX7-ALIGNED-NEXT:    s_add_u32 s2, s0, 2
59; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v1, s1
60; GFX7-ALIGNED-NEXT:    flat_store_short v[0:1], v2
61; GFX7-ALIGNED-NEXT:    s_addc_u32 s3, s1, 0
62; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v0, s2
63; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v2, 2
64; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v1, s3
65; GFX7-ALIGNED-NEXT:    flat_store_short v[0:1], v2
66; GFX7-ALIGNED-NEXT:    s_endpgm
67;
68; GFX7-UNALIGNED-LABEL: global_store_2xi16_align2:
69; GFX7-UNALIGNED:       ; %bb.0:
70; GFX7-UNALIGNED-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
71; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v2, 1
72; GFX7-UNALIGNED-NEXT:    s_waitcnt lgkmcnt(0)
73; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v0, s0
74; GFX7-UNALIGNED-NEXT:    s_add_u32 s2, s0, 2
75; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v1, s1
76; GFX7-UNALIGNED-NEXT:    flat_store_short v[0:1], v2
77; GFX7-UNALIGNED-NEXT:    s_addc_u32 s3, s1, 0
78; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v0, s2
79; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v2, 2
80; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v1, s3
81; GFX7-UNALIGNED-NEXT:    flat_store_short v[0:1], v2
82; GFX7-UNALIGNED-NEXT:    s_endpgm
83;
84; GFX9-LABEL: global_store_2xi16_align2:
85; GFX9:       ; %bb.0:
86; GFX9-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
87; GFX9-NEXT:    v_mov_b32_e32 v0, 0
88; GFX9-NEXT:    v_mov_b32_e32 v1, 1
89; GFX9-NEXT:    v_mov_b32_e32 v2, 2
90; GFX9-NEXT:    s_waitcnt lgkmcnt(0)
91; GFX9-NEXT:    global_store_short v0, v1, s[0:1]
92; GFX9-NEXT:    global_store_short v0, v2, s[0:1] offset:2
93; GFX9-NEXT:    s_endpgm
94  %gep.r = getelementptr i16, i16 addrspace(1)* %r, i64 1
95  store i16 1, i16 addrspace(1)* %r, align 2
96  store i16 2, i16 addrspace(1)* %gep.r, align 2
97  ret void
98}
99
100; Should produce align 1 dword when legal
101define i32 @global_load_2xi16_align1(i16 addrspace(1)* %p) #0 {
102; GFX7-ALIGNED-LABEL: global_load_2xi16_align1:
103; GFX7-ALIGNED:       ; %bb.0:
104; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
105; GFX7-ALIGNED-NEXT:    v_add_i32_e32 v2, vcc, 2, v0
106; GFX7-ALIGNED-NEXT:    v_addc_u32_e32 v3, vcc, 0, v1, vcc
107; GFX7-ALIGNED-NEXT:    v_add_i32_e32 v4, vcc, 1, v0
108; GFX7-ALIGNED-NEXT:    v_addc_u32_e32 v5, vcc, 0, v1, vcc
109; GFX7-ALIGNED-NEXT:    v_add_i32_e32 v6, vcc, 3, v0
110; GFX7-ALIGNED-NEXT:    v_addc_u32_e32 v7, vcc, 0, v1, vcc
111; GFX7-ALIGNED-NEXT:    flat_load_ubyte v0, v[0:1]
112; GFX7-ALIGNED-NEXT:    flat_load_ubyte v1, v[6:7]
113; GFX7-ALIGNED-NEXT:    flat_load_ubyte v4, v[4:5]
114; GFX7-ALIGNED-NEXT:    flat_load_ubyte v2, v[2:3]
115; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(2)
116; GFX7-ALIGNED-NEXT:    v_lshlrev_b32_e32 v1, 8, v1
117; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(1)
118; GFX7-ALIGNED-NEXT:    v_lshlrev_b32_e32 v3, 8, v4
119; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(0)
120; GFX7-ALIGNED-NEXT:    v_or_b32_e32 v1, v1, v2
121; GFX7-ALIGNED-NEXT:    v_or_b32_e32 v0, v3, v0
122; GFX7-ALIGNED-NEXT:    v_lshlrev_b32_e32 v1, 16, v1
123; GFX7-ALIGNED-NEXT:    v_or_b32_e32 v0, v0, v1
124; GFX7-ALIGNED-NEXT:    s_setpc_b64 s[30:31]
125;
126; GFX7-UNALIGNED-LABEL: global_load_2xi16_align1:
127; GFX7-UNALIGNED:       ; %bb.0:
128; GFX7-UNALIGNED-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
129; GFX7-UNALIGNED-NEXT:    flat_load_dword v0, v[0:1]
130; GFX7-UNALIGNED-NEXT:    s_waitcnt vmcnt(0)
131; GFX7-UNALIGNED-NEXT:    s_setpc_b64 s[30:31]
132;
133; GFX9-LABEL: global_load_2xi16_align1:
134; GFX9:       ; %bb.0:
135; GFX9-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
136; GFX9-NEXT:    global_load_dword v0, v[0:1], off
137; GFX9-NEXT:    v_mov_b32_e32 v1, 0xffff
138; GFX9-NEXT:    s_mov_b32 s4, 0xffff
139; GFX9-NEXT:    s_waitcnt vmcnt(0)
140; GFX9-NEXT:    v_bfi_b32 v1, v1, 0, v0
141; GFX9-NEXT:    v_and_or_b32 v0, v0, s4, v1
142; GFX9-NEXT:    s_setpc_b64 s[30:31]
143  %gep.p = getelementptr i16, i16 addrspace(1)* %p, i64 1
144  %p.0 = load i16, i16 addrspace(1)* %p, align 1
145  %p.1 = load i16, i16 addrspace(1)* %gep.p, align 1
146  %zext.0 = zext i16 %p.0 to i32
147  %zext.1 = zext i16 %p.1 to i32
148  %shl.1 = shl i32 %zext.1, 16
149  %or = or i32 %zext.0, %shl.1
150  ret i32 %or
151}
152
153; Should produce align 1 dword when legal
154define amdgpu_kernel void @global_store_2xi16_align1(i16 addrspace(1)* %p, i16 addrspace(1)* %r) #0 {
155; GFX7-ALIGNED-LABEL: global_store_2xi16_align1:
156; GFX7-ALIGNED:       ; %bb.0:
157; GFX7-ALIGNED-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
158; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v2, 1
159; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v3, 0
160; GFX7-ALIGNED-NEXT:    s_waitcnt lgkmcnt(0)
161; GFX7-ALIGNED-NEXT:    s_add_u32 s2, s0, 2
162; GFX7-ALIGNED-NEXT:    s_addc_u32 s3, s1, 0
163; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v0, s0
164; GFX7-ALIGNED-NEXT:    s_add_u32 s4, s0, 1
165; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v1, s1
166; GFX7-ALIGNED-NEXT:    s_addc_u32 s5, s1, 0
167; GFX7-ALIGNED-NEXT:    flat_store_byte v[0:1], v2
168; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v0, s4
169; GFX7-ALIGNED-NEXT:    s_add_u32 s0, s0, 3
170; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v1, s5
171; GFX7-ALIGNED-NEXT:    flat_store_byte v[0:1], v3
172; GFX7-ALIGNED-NEXT:    s_addc_u32 s1, s1, 0
173; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v0, s0
174; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v1, s1
175; GFX7-ALIGNED-NEXT:    flat_store_byte v[0:1], v3
176; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v0, s2
177; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v2, 2
178; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v1, s3
179; GFX7-ALIGNED-NEXT:    flat_store_byte v[0:1], v2
180; GFX7-ALIGNED-NEXT:    s_endpgm
181;
182; GFX7-UNALIGNED-LABEL: global_store_2xi16_align1:
183; GFX7-UNALIGNED:       ; %bb.0:
184; GFX7-UNALIGNED-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
185; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v2, 0x20001
186; GFX7-UNALIGNED-NEXT:    s_waitcnt lgkmcnt(0)
187; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v0, s0
188; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v1, s1
189; GFX7-UNALIGNED-NEXT:    flat_store_dword v[0:1], v2
190; GFX7-UNALIGNED-NEXT:    s_endpgm
191;
192; GFX9-LABEL: global_store_2xi16_align1:
193; GFX9:       ; %bb.0:
194; GFX9-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
195; GFX9-NEXT:    v_mov_b32_e32 v0, 0
196; GFX9-NEXT:    v_mov_b32_e32 v1, 0x20001
197; GFX9-NEXT:    s_waitcnt lgkmcnt(0)
198; GFX9-NEXT:    global_store_dword v0, v1, s[0:1]
199; GFX9-NEXT:    s_endpgm
200  %gep.r = getelementptr i16, i16 addrspace(1)* %r, i64 1
201  store i16 1, i16 addrspace(1)* %r, align 1
202  store i16 2, i16 addrspace(1)* %gep.r, align 1
203  ret void
204}
205
206; Should merge this to a dword load
207define i32 @global_load_2xi16_align4(i16 addrspace(1)* %p) #0 {
208; GFX7-LABEL: load_2xi16_align4:
209; GFX7:       ; %bb.0:
210; GFX7-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
211; GFX7-NEXT:    flat_load_dword v0, v[0:1]
212; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
213; GFX7-NEXT:    s_setpc_b64 s[30:31]
214;
215; GFX7-ALIGNED-LABEL: global_load_2xi16_align4:
216; GFX7-ALIGNED:       ; %bb.0:
217; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
218; GFX7-ALIGNED-NEXT:    flat_load_dword v0, v[0:1]
219; GFX7-ALIGNED-NEXT:    s_waitcnt vmcnt(0)
220; GFX7-ALIGNED-NEXT:    s_setpc_b64 s[30:31]
221;
222; GFX7-UNALIGNED-LABEL: global_load_2xi16_align4:
223; GFX7-UNALIGNED:       ; %bb.0:
224; GFX7-UNALIGNED-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
225; GFX7-UNALIGNED-NEXT:    flat_load_dword v0, v[0:1]
226; GFX7-UNALIGNED-NEXT:    s_waitcnt vmcnt(0)
227; GFX7-UNALIGNED-NEXT:    s_setpc_b64 s[30:31]
228;
229; GFX9-LABEL: global_load_2xi16_align4:
230; GFX9:       ; %bb.0:
231; GFX9-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
232; GFX9-NEXT:    global_load_dword v0, v[0:1], off
233; GFX9-NEXT:    v_mov_b32_e32 v1, 0xffff
234; GFX9-NEXT:    s_mov_b32 s4, 0xffff
235; GFX9-NEXT:    s_waitcnt vmcnt(0)
236; GFX9-NEXT:    v_bfi_b32 v1, v1, 0, v0
237; GFX9-NEXT:    v_and_or_b32 v0, v0, s4, v1
238; GFX9-NEXT:    s_setpc_b64 s[30:31]
239  %gep.p = getelementptr i16, i16 addrspace(1)* %p, i64 1
240  %p.0 = load i16, i16 addrspace(1)* %p, align 4
241  %p.1 = load i16, i16 addrspace(1)* %gep.p, align 2
242  %zext.0 = zext i16 %p.0 to i32
243  %zext.1 = zext i16 %p.1 to i32
244  %shl.1 = shl i32 %zext.1, 16
245  %or = or i32 %zext.0, %shl.1
246  ret i32 %or
247}
248
249; Should merge this to a dword store
250define amdgpu_kernel void @global_store_2xi16_align4(i16 addrspace(1)* %p, i16 addrspace(1)* %r) #0 {
251; GFX7-LABEL: global_store_2xi16_align4:
252; GFX7:       ; %bb.0:
253; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
254; GFX7-NEXT:    v_mov_b32_e32 v2, 0x20001
255; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
256; GFX7-NEXT:    v_mov_b32_e32 v0, s0
257; GFX7-NEXT:    v_mov_b32_e32 v1, s1
258; GFX7-NEXT:    flat_store_dword v[0:1], v2
259; GFX7-NEXT:    s_endpgm
260;
261; GFX7-ALIGNED-LABEL: global_store_2xi16_align4:
262; GFX7-ALIGNED:       ; %bb.0:
263; GFX7-ALIGNED-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
264; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v2, 0x20001
265; GFX7-ALIGNED-NEXT:    s_waitcnt lgkmcnt(0)
266; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v0, s0
267; GFX7-ALIGNED-NEXT:    v_mov_b32_e32 v1, s1
268; GFX7-ALIGNED-NEXT:    flat_store_dword v[0:1], v2
269; GFX7-ALIGNED-NEXT:    s_endpgm
270;
271; GFX7-UNALIGNED-LABEL: global_store_2xi16_align4:
272; GFX7-UNALIGNED:       ; %bb.0:
273; GFX7-UNALIGNED-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
274; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v2, 0x20001
275; GFX7-UNALIGNED-NEXT:    s_waitcnt lgkmcnt(0)
276; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v0, s0
277; GFX7-UNALIGNED-NEXT:    v_mov_b32_e32 v1, s1
278; GFX7-UNALIGNED-NEXT:    flat_store_dword v[0:1], v2
279; GFX7-UNALIGNED-NEXT:    s_endpgm
280;
281; GFX9-LABEL: global_store_2xi16_align4:
282; GFX9:       ; %bb.0:
283; GFX9-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
284; GFX9-NEXT:    v_mov_b32_e32 v0, 0
285; GFX9-NEXT:    v_mov_b32_e32 v1, 0x20001
286; GFX9-NEXT:    s_waitcnt lgkmcnt(0)
287; GFX9-NEXT:    global_store_dword v0, v1, s[0:1]
288; GFX9-NEXT:    s_endpgm
289  %gep.r = getelementptr i16, i16 addrspace(1)* %r, i64 1
290  store i16 1, i16 addrspace(1)* %r, align 4
291  store i16 2, i16 addrspace(1)* %gep.r, align 2
292  ret void
293}
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327