1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx906 --verify-machineinstrs -o - %s | FileCheck -check-prefix=GCN %s
3 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx906 -O0 --verify-machineinstrs -o - %s | FileCheck -check-prefix=GCN-O0 %s
5 ; Test whole-wave register spilling.
7 ; In this testcase, the return address registers, PC value (SGPR30_SGPR31) and the scratch SGPR used in
8 ; the inline asm statements should be preserved across the call. Since the test limits the VGPR numbers,
9 ; the PC will be spilled to the only available CSR VGPR (VGPR40) as we spill CSR SGPRs including the PC
10 ; directly to the physical VGPR lane to correctly generate the CFIs. The SGPR20 will get spilled to the
11 ; virtual VGPR lane and that would be allocated by regalloc. Since there is no free VGPR to allocate, RA
12 ; must spill a scratch VGPR. The writelane/readlane instructions that spill/restore SGPRs into/from VGPR
13 ; are whole-wave operations and hence the VGPRs involved in such operations require whole-wave spilling.
15 define void @test() #0 {
18 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
19 ; GCN-NEXT: s_mov_b32 s16, s33
20 ; GCN-NEXT: s_mov_b32 s33, s32
21 ; GCN-NEXT: s_xor_saveexec_b64 s[18:19], -1
22 ; GCN-NEXT: buffer_store_dword v0, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
23 ; GCN-NEXT: buffer_store_dword v1, off, s[0:3], s33 offset:12 ; 4-byte Folded Spill
24 ; GCN-NEXT: s_mov_b64 exec, -1
25 ; GCN-NEXT: buffer_store_dword v40, off, s[0:3], s33 ; 4-byte Folded Spill
26 ; GCN-NEXT: s_mov_b64 exec, s[18:19]
27 ; GCN-NEXT: v_writelane_b32 v40, s16, 4
28 ; GCN-NEXT: v_writelane_b32 v40, s28, 2
29 ; GCN-NEXT: v_writelane_b32 v40, s29, 3
30 ; GCN-NEXT: ; implicit-def: $vgpr0 : SGPR spill to VGPR lane
31 ; GCN-NEXT: v_writelane_b32 v40, s30, 0
32 ; GCN-NEXT: s_addk_i32 s32, 0x800
33 ; GCN-NEXT: v_writelane_b32 v40, s31, 1
34 ; GCN-NEXT: ;;#ASMSTART
37 ; GCN-NEXT: v_writelane_b32 v0, s16, 0
38 ; GCN-NEXT: s_or_saveexec_b64 s[28:29], -1
39 ; GCN-NEXT: buffer_store_dword v0, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
40 ; GCN-NEXT: s_mov_b64 exec, s[28:29]
41 ; GCN-NEXT: s_getpc_b64 s[16:17]
42 ; GCN-NEXT: s_add_u32 s16, s16, ext_func@gotpcrel32@lo+4
43 ; GCN-NEXT: s_addc_u32 s17, s17, ext_func@gotpcrel32@hi+12
44 ; GCN-NEXT: s_load_dwordx2 s[16:17], s[16:17], 0x0
45 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
46 ; GCN-NEXT: s_swappc_b64 s[30:31], s[16:17]
47 ; GCN-NEXT: s_or_saveexec_b64 s[28:29], -1
48 ; GCN-NEXT: buffer_load_dword v1, off, s[0:3], s33 offset:4 ; 4-byte Folded Reload
49 ; GCN-NEXT: s_mov_b64 exec, s[28:29]
50 ; GCN-NEXT: s_waitcnt vmcnt(0)
51 ; GCN-NEXT: v_readlane_b32 s4, v1, 0
52 ; GCN-NEXT: v_mov_b32_e32 v0, s4
53 ; GCN-NEXT: global_store_dword v[0:1], v0, off
54 ; GCN-NEXT: s_waitcnt vmcnt(0)
55 ; GCN-NEXT: v_readlane_b32 s31, v40, 1
56 ; GCN-NEXT: v_readlane_b32 s30, v40, 0
57 ; GCN-NEXT: ; kill: killed $vgpr1
58 ; GCN-NEXT: v_readlane_b32 s4, v40, 4
59 ; GCN-NEXT: v_readlane_b32 s28, v40, 2
60 ; GCN-NEXT: v_readlane_b32 s29, v40, 3
61 ; GCN-NEXT: s_xor_saveexec_b64 s[6:7], -1
62 ; GCN-NEXT: buffer_load_dword v0, off, s[0:3], s33 offset:8 ; 4-byte Folded Reload
63 ; GCN-NEXT: buffer_load_dword v1, off, s[0:3], s33 offset:12 ; 4-byte Folded Reload
64 ; GCN-NEXT: s_mov_b64 exec, -1
65 ; GCN-NEXT: buffer_load_dword v40, off, s[0:3], s33 ; 4-byte Folded Reload
66 ; GCN-NEXT: s_mov_b64 exec, s[6:7]
67 ; GCN-NEXT: s_addk_i32 s32, 0xf800
68 ; GCN-NEXT: s_mov_b32 s33, s4
69 ; GCN-NEXT: s_waitcnt vmcnt(0)
70 ; GCN-NEXT: s_setpc_b64 s[30:31]
74 ; GCN-O0-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
75 ; GCN-O0-NEXT: s_mov_b32 s16, s33
76 ; GCN-O0-NEXT: s_mov_b32 s33, s32
77 ; GCN-O0-NEXT: s_xor_saveexec_b64 s[18:19], -1
78 ; GCN-O0-NEXT: buffer_store_dword v0, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
79 ; GCN-O0-NEXT: s_mov_b64 exec, -1
80 ; GCN-O0-NEXT: buffer_store_dword v40, off, s[0:3], s33 ; 4-byte Folded Spill
81 ; GCN-O0-NEXT: s_mov_b64 exec, s[18:19]
82 ; GCN-O0-NEXT: v_writelane_b32 v40, s16, 4
83 ; GCN-O0-NEXT: v_writelane_b32 v40, s28, 2
84 ; GCN-O0-NEXT: v_writelane_b32 v40, s29, 3
85 ; GCN-O0-NEXT: s_add_i32 s32, s32, 0x400
86 ; GCN-O0-NEXT: ; implicit-def: $vgpr0 : SGPR spill to VGPR lane
87 ; GCN-O0-NEXT: v_writelane_b32 v40, s30, 0
88 ; GCN-O0-NEXT: v_writelane_b32 v40, s31, 1
89 ; GCN-O0-NEXT: ;;#ASMSTART
90 ; GCN-O0-NEXT: ; def s16
91 ; GCN-O0-NEXT: ;;#ASMEND
92 ; GCN-O0-NEXT: v_writelane_b32 v0, s16, 0
93 ; GCN-O0-NEXT: s_or_saveexec_b64 s[28:29], -1
94 ; GCN-O0-NEXT: buffer_store_dword v0, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
95 ; GCN-O0-NEXT: s_mov_b64 exec, s[28:29]
96 ; GCN-O0-NEXT: s_getpc_b64 s[16:17]
97 ; GCN-O0-NEXT: s_add_u32 s16, s16, ext_func@gotpcrel32@lo+4
98 ; GCN-O0-NEXT: s_addc_u32 s17, s17, ext_func@gotpcrel32@hi+12
99 ; GCN-O0-NEXT: s_load_dwordx2 s[16:17], s[16:17], 0x0
100 ; GCN-O0-NEXT: s_mov_b64 s[22:23], s[2:3]
101 ; GCN-O0-NEXT: s_mov_b64 s[20:21], s[0:1]
102 ; GCN-O0-NEXT: s_mov_b64 s[0:1], s[20:21]
103 ; GCN-O0-NEXT: s_mov_b64 s[2:3], s[22:23]
104 ; GCN-O0-NEXT: s_waitcnt lgkmcnt(0)
105 ; GCN-O0-NEXT: s_swappc_b64 s[30:31], s[16:17]
106 ; GCN-O0-NEXT: s_or_saveexec_b64 s[28:29], -1
107 ; GCN-O0-NEXT: buffer_load_dword v0, off, s[0:3], s33 offset:4 ; 4-byte Folded Reload
108 ; GCN-O0-NEXT: s_mov_b64 exec, s[28:29]
109 ; GCN-O0-NEXT: s_waitcnt vmcnt(0)
110 ; GCN-O0-NEXT: v_readlane_b32 s4, v0, 0
111 ; GCN-O0-NEXT: ; implicit-def: $sgpr6_sgpr7
112 ; GCN-O0-NEXT: v_mov_b32_e32 v1, s6
113 ; GCN-O0-NEXT: v_mov_b32_e32 v2, s7
114 ; GCN-O0-NEXT: v_mov_b32_e32 v3, s4
115 ; GCN-O0-NEXT: global_store_dword v[1:2], v3, off
116 ; GCN-O0-NEXT: s_waitcnt vmcnt(0)
117 ; GCN-O0-NEXT: v_readlane_b32 s31, v40, 1
118 ; GCN-O0-NEXT: v_readlane_b32 s30, v40, 0
119 ; GCN-O0-NEXT: ; kill: killed $vgpr0
120 ; GCN-O0-NEXT: v_readlane_b32 s4, v40, 4
121 ; GCN-O0-NEXT: v_readlane_b32 s28, v40, 2
122 ; GCN-O0-NEXT: v_readlane_b32 s29, v40, 3
123 ; GCN-O0-NEXT: s_xor_saveexec_b64 s[6:7], -1
124 ; GCN-O0-NEXT: buffer_load_dword v0, off, s[0:3], s33 offset:8 ; 4-byte Folded Reload
125 ; GCN-O0-NEXT: s_mov_b64 exec, -1
126 ; GCN-O0-NEXT: buffer_load_dword v40, off, s[0:3], s33 ; 4-byte Folded Reload
127 ; GCN-O0-NEXT: s_mov_b64 exec, s[6:7]
128 ; GCN-O0-NEXT: s_add_i32 s32, s32, 0xfffffc00
129 ; GCN-O0-NEXT: s_mov_b32 s33, s4
130 ; GCN-O0-NEXT: s_waitcnt vmcnt(0)
131 ; GCN-O0-NEXT: s_setpc_b64 s[30:31]
132 %sgpr = call i32 asm sideeffect "; def $0", "=s" () #0
133 call void @ext_func()
134 store volatile i32 %sgpr, ptr addrspace(1) undef
138 declare void @ext_func();
140 attributes #0 = { nounwind "amdgpu-num-vgpr"="41" "amdgpu-num-sgpr"="34"}