1; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX9 %s
2; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX10 %s
3
4declare void @extern_func()
5
6define <4 x float> @non_preserved_vgpr_tuple8(<8 x i32> %rsrc, <4 x i32> %samp, float %bias, float %zcompare, float %s, float %t, float %clamp) {
7; The vgpr tuple8 operand in image_gather4_c_b_cl instruction needs not be
8; preserved across the call and should get 8 scratch registers.
9
10; GFX9-LABEL: non_preserved_vgpr_tuple8:
11; GFX9: buffer_store_dword v44, off, s[0:3], s32 offset:16 ; 4-byte Folded Spill
12; GFX9: buffer_store_dword v40, off, s[0:3], s33 offset:12 ; 4-byte Folded Spill
13; GFX9-NEXT: buffer_store_dword v41, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
14; GFX9-NEXT: buffer_store_dword v42, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
15; GFX9-NEXT: buffer_store_dword v43, off, s[0:3], s33 ; 4-byte Folded Spill
16
17; GFX9: v_mov_b32_e32 v36, v16
18; GFX9-NEXT: v_mov_b32_e32 v35, v15
19; GFX9-NEXT: v_mov_b32_e32 v34, v14
20; GFX9-NEXT: v_mov_b32_e32 v33, v13
21; GFX9-NEXT: v_mov_b32_e32 v32, v12
22; GFX9: ;;#ASMSTART
23; GFX9-NEXT: ;;#ASMEND
24; GFX9: image_gather4_c_b_cl v[40:43], v[32:39], s[4:11], s[4:7] dmask:0x1
25; GFX9-NEXT: s_getpc_b64 s[4:5]
26; GFX9-NEXT: s_add_u32 s4, s4, extern_func@gotpcrel32@lo+4
27; GFX9-NEXT: s_addc_u32 s5, s5, extern_func@gotpcrel32@hi+12
28; GFX9-NEXT: s_load_dwordx2 s[4:5], s[4:5], 0x0
29; GFX9-NEXT: v_writelane_b32 v44, s30, 0
30; GFX9: s_waitcnt lgkmcnt(0)
31; GFX9-NEXT: s_swappc_b64 s[30:31], s[4:5]
32
33; GFX9: buffer_load_dword v43, off, s[0:3], s33 ; 4-byte Folded Reload
34; GFX9-NEXT: buffer_load_dword v42, off, s[0:3], s33 offset:4 ; 4-byte Folded Reload
35; GFX9-NEXT: buffer_load_dword v41, off, s[0:3], s33 offset:8 ; 4-byte Folded Reload
36; GFX9-NEXT: buffer_load_dword v40, off, s[0:3], s33 offset:12 ; 4-byte Folded Reload
37; GFX9: buffer_load_dword v44, off, s[0:3], s32 offset:16 ; 4-byte Folded Reload
38; GFX9: s_setpc_b64 s[4:5]
39;
40; GFX10-LABEL: non_preserved_vgpr_tuple8:
41; GFX10: buffer_store_dword v44, off, s[0:3], s32 offset:16 ; 4-byte Folded Spill
42; GFX10: buffer_store_dword v40, off, s[0:3], s33 offset:12 ; 4-byte Folded Spill
43; GFX10-NEXT: buffer_store_dword v41, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
44; GFX10-NEXT: buffer_store_dword v42, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
45; GFX10-NEXT: buffer_store_dword v43, off, s[0:3], s33 ; 4-byte Folded Spill
46
47; GFX10: v_mov_b32_e32 v36, v16
48; GFX10-NEXT: v_mov_b32_e32 v35, v15
49; GFX10-NEXT: v_mov_b32_e32 v34, v14
50; GFX10-NEXT: v_mov_b32_e32 v33, v13
51; GFX10-NEXT: v_mov_b32_e32 v32, v12
52
53; GFX10: ;;#ASMSTART
54; GFX10-NEXT: ;;#ASMEND
55
56; GFX10: image_gather4_c_b_cl v[40:43], v[32:39], s[4:11], s[4:7] dmask:0x1 dim:SQ_RSRC_IMG_2D
57; GFX10-NEXT: s_waitcnt_depctr 0xffe3
58; GFX10-NEXT: s_getpc_b64 s[4:5]
59; GFX10-NEXT: s_add_u32 s4, s4, extern_func@gotpcrel32@lo+4
60; GFX10-NEXT: s_addc_u32 s5, s5, extern_func@gotpcrel32@hi+12
61; GFX10: s_load_dwordx2 s[4:5], s[4:5], 0x0
62; GFX10-NEXT:                                 ; implicit-def: $vcc_hi
63; GFX10: s_waitcnt lgkmcnt(0)
64; GFX10-NEXT: s_swappc_b64 s[30:31], s[4:5]
65
66; GFX10: buffer_load_dword v43, off, s[0:3], s33
67; GFX10-NEXT: buffer_load_dword v42, off, s[0:3], s33 offset:4
68; GFX10-NEXT: buffer_load_dword v41, off, s[0:3], s33 offset:8
69; GFX10-NEXT: buffer_load_dword v40, off, s[0:3], s33 offset:12
70
71; GFX10: buffer_load_dword v44, off, s[0:3], s32 offset:16 ; 4-byte Folded Reload
72; GFX10: s_setpc_b64 s[4:5]
73main_body:
74  call void asm sideeffect "", "~{v0},~{v1},~{v2},~{v3},~{v4},~{v5},~{v6},~{v7}"() #0
75  call void asm sideeffect "", "~{v8},~{v9},~{v10},~{v11},~{v12},~{v13},~{v14},~{v15}"() #0
76  call void asm sideeffect "", "~{v16},~{v17},~{v18},~{v19},~{v20},~{v21},~{v22},~{v23}"() #0
77  call void asm sideeffect "", "~{v24},~{v25},~{v26},~{v27},~{v28},~{v29},~{v30},~{v31}"() #0
78  %v = call <4 x float> @llvm.amdgcn.image.gather4.c.b.cl.2d.v4f32.f32.f32(i32 1, float %bias, float %zcompare, float %s, float %t, float %clamp, <8 x i32> undef, <4 x i32> undef, i1 false, i32 0, i32 0)
79  call void @extern_func()
80  ret <4 x float> %v
81}
82
83define <4 x float> @call_preserved_vgpr_tuple8(<8 x i32> %rsrc, <4 x i32> %samp, float %bias, float %zcompare, float %s, float %t, float %clamp) {
84; The vgpr tuple8 operand in image_gather4_c_b_cl instruction needs to be preserved
85; across the call and should get allcoated to 8 CSRs.
86; Only the lower 5 sub-registers of the tuple are preserved.
87; The upper 3 sub-registers are unused.
88
89; GFX9-LABEL: call_preserved_vgpr_tuple8:
90; GFX9: buffer_store_dword v56, off, s[0:3], s32 offset:20 ; 4-byte Folded Spill
91; GFX9: buffer_store_dword v40, off, s[0:3], s33 offset:16 ; 4-byte Folded Spill
92; GFX9-NEXT: buffer_store_dword v41, off, s[0:3], s33 offset:12 ; 4-byte Folded Spill
93; GFX9-NEXT: buffer_store_dword v42, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
94; GFX9-NEXT: buffer_store_dword v43, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
95; GFX9-NEXT: buffer_store_dword v44, off, s[0:3], s33 ; 4-byte Folded Spill
96
97; GFX9: v_mov_b32_e32 v44, v16
98; GFX9-NEXT: v_mov_b32_e32 v43, v15
99; GFX9-NEXT: v_mov_b32_e32 v42, v14
100; GFX9-NEXT: v_mov_b32_e32 v41, v13
101; GFX9-NEXT: v_mov_b32_e32 v40, v12
102
103; GFX9: image_gather4_c_b_cl v[0:3], v[40:47], s[36:43], s[4:7] dmask:0x1
104; GFX9-NEXT: s_getpc_b64 s[4:5]
105; GFX9-NEXT: s_add_u32 s4, s4, extern_func@gotpcrel32@lo+4
106; GFX9-NEXT: s_addc_u32 s5, s5, extern_func@gotpcrel32@hi+12
107; GFX9-NEXT: s_load_dwordx2 s[4:5], s[4:5], 0x0
108; GFX9: s_waitcnt vmcnt(0)
109; GFX9-NEXT: global_store_dwordx4 v[0:1], v[0:3], off
110; GFX9-NEXT: s_waitcnt lgkmcnt(0)
111; GFX9-NEXT: s_swappc_b64 s[30:31], s[4:5]
112; GFX9-NEXT: image_gather4_c_b_cl v[0:3], v[40:47], s[36:43], s[4:7] dmask:0x1
113
114; GFX9: buffer_load_dword v44, off, s[0:3], s33 ; 4-byte Folded Reload
115; GFX9-NEXT: buffer_load_dword v43, off, s[0:3], s33 offset:4 ; 4-byte Folded Reload
116; GFX9-NEXT: buffer_load_dword v42, off, s[0:3], s33 offset:8 ; 4-byte Folded Reload
117; GFX9-NEXT: buffer_load_dword v41, off, s[0:3], s33 offset:12 ; 4-byte Folded Reload
118; GFX9-NEXT: buffer_load_dword v40, off, s[0:3], s33 offset:16 ; 4-byte Folded Reload
119
120; GFX9: buffer_load_dword v56, off, s[0:3], s32 offset:20 ; 4-byte Folded Reload
121; GFX9: s_setpc_b64 s[4:5]
122;
123; GFX10-LABEL: call_preserved_vgpr_tuple8:
124; GFX10: buffer_store_dword v45, off, s[0:3], s32 offset:20 ; 4-byte Folded Spill
125; GFX10: buffer_store_dword v40, off, s[0:3], s33 offset:16 ; 4-byte Folded Spill
126; GFX10-NEXT: buffer_store_dword v41, off, s[0:3], s33 offset:12 ; 4-byte Folded Spill
127; GFX10-NEXT: buffer_store_dword v42, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
128; GFX10-NEXT: buffer_store_dword v43, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
129; GFX10-NEXT: buffer_store_dword v44, off, s[0:3], s33 ; 4-byte Folded Spill
130
131
132; GFX10:      image_gather4_c_b_cl v[0:3], v[12:19], s[36:43], s[4:7] dmask:0x1 dim:SQ_RSRC_IMG_2D
133; GFX10-NEXT: s_waitcnt_depctr 0xffe3
134; GFX10-NEXT: s_getpc_b64 s[4:5]
135; GFX10-NEXT: s_add_u32 s4, s4, extern_func@gotpcrel32@lo+4
136; GFX10-NEXT: s_addc_u32 s5, s5, extern_func@gotpcrel32@hi+12
137; GFX10-NEXT: v_mov_b32_e32 v40, v16
138; GFX10-NEXT: s_load_dwordx2 s[4:5], s[4:5], 0x0
139; GFX10-NEXT: v_mov_b32_e32 v41, v15
140; GFX10-NEXT: v_mov_b32_e32 v42, v14
141; GFX10-NEXT: v_mov_b32_e32 v43, v13
142; GFX10-NEXT: v_mov_b32_e32 v44, v12
143; GFX10-NEXT: ; implicit-def: $vcc_hi
144; GFX10-NEXT: s_waitcnt vmcnt(0)
145; GFX10-NEXT: global_store_dwordx4 v[0:1], v[0:3], off
146; GFX10-NEXT: s_waitcnt lgkmcnt(0)
147; GFX10-NEXT: s_swappc_b64 s[30:31], s[4:5]
148; GFX10-NEXT: image_gather4_c_b_cl v[0:3], [v44, v43, v42, v41, v40], s[36:43], s[4:7] dmask:0x1 dim:SQ_RSRC_IMG_2D
149
150; GFX10: buffer_load_dword v44, off, s[0:3], s33
151; GFX10-NEXT: buffer_load_dword v43, off, s[0:3], s33 offset:4
152; GFX10-NEXT: buffer_load_dword v42, off, s[0:3], s33 offset:8
153; GFX10-NEXT: buffer_load_dword v41, off, s[0:3], s33 offset:12
154; GFX10-NEXT: buffer_load_dword v40, off, s[0:3], s33 offset:16
155; GFX10: buffer_load_dword v45, off, s[0:3], s32 offset:20
156; GFX10: s_setpc_b64 s[4:5]
157main_body:
158  %v = call <4 x float> @llvm.amdgcn.image.gather4.c.b.cl.2d.v4f32.f32.f32(i32 1, float %bias, float %zcompare, float %s, float %t, float %clamp, <8 x i32> undef, <4 x i32> undef, i1 false, i32 0, i32 0)
159  store <4 x float> %v, <4 x float> addrspace(1)* undef
160  call void @extern_func()
161  %v1 = call <4 x float> @llvm.amdgcn.image.gather4.c.b.cl.2d.v4f32.f32.f32(i32 1, float %bias, float %zcompare, float %s, float %t, float %clamp, <8 x i32> undef, <4 x i32> undef, i1 false, i32 0, i32 0)
162  ret <4 x float> %v1
163}
164
165declare <4 x float> @llvm.amdgcn.image.gather4.c.b.cl.2d.v4f32.f32.f32(i32 immarg, float, float, float, float, float, <8 x i32>, <4 x i32>, i1 immarg, i32 immarg, i32 immarg) #1
166
167attributes #0 = { nounwind writeonly }
168attributes #1 = { nounwind readonly }
169