1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=kaveri -mattr=-promote-alloca -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN %s
3 ; Test that non-entry function frame indices are expanded properly to
4 ; give an index relative to the scratch wave offset register
6 ; Materialize into a mov. Make sure there isn't an unnecessary copy.
7 ; GCN-LABEL: {{^}}func_mov_fi_i32:
8 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
9 ; GCN: s_sub_u32 s6, s5, s4
10 ; GCN-NEXT: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s6, 6
11 ; GCN-NEXT: v_add_i32_e64 v0, s[6:7], 4, [[SCALED]]
13 ; GCN: ds_write_b32 v0, v0
14 define void @func_mov_fi_i32() #0 {
16 store volatile i32* %alloca, i32* addrspace(3)* undef
20 ; Materialize into an add of a constant offset from the FI.
21 ; FIXME: Should be able to merge adds
23 ; GCN-LABEL: {{^}}func_add_constant_to_fi_i32:
24 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
25 ; GCN: s_sub_u32 s6, s5, s4
26 ; GCN-NEXT: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s6, 6
27 ; GCN-NEXT: v_add_i32_e64 v0, s[6:7], 4, [[SCALED]]
28 ; GCN-NEXT: v_add_i32_e32 v0, vcc, 4, v0
30 ; GCN: ds_write_b32 v0, v0
31 define void @func_add_constant_to_fi_i32() #0 {
32 %alloca = alloca [2 x i32], align 4
33 %gep0 = getelementptr inbounds [2 x i32], [2 x i32]* %alloca, i32 0, i32 1
34 store volatile i32* %gep0, i32* addrspace(3)* undef
38 ; A user the materialized frame index can't be meaningfully folded
41 ; GCN-LABEL: {{^}}func_other_fi_user_i32:
42 ; GCN: s_sub_u32 s6, s5, s4
43 ; GCN-NEXT: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s6, 6
44 ; GCN-NEXT: v_add_i32_e64 v0, s[6:7], 4, [[SCALED]]
45 ; GCN-NEXT: v_mul_lo_i32 v0, v0, 9
47 ; GCN: ds_write_b32 v0, v0
48 define void @func_other_fi_user_i32() #0 {
49 %alloca = alloca [2 x i32], align 4
50 %ptrtoint = ptrtoint [2 x i32]* %alloca to i32
51 %mul = mul i32 %ptrtoint, 9
52 store volatile i32 %mul, i32 addrspace(3)* undef
56 ; GCN-LABEL: {{^}}func_store_private_arg_i32_ptr:
57 ; GCN: v_mov_b32_e32 v1, 15{{$}}
58 ; GCN: buffer_store_dword v1, v0, s[0:3], s4 offen{{$}}
59 define void @func_store_private_arg_i32_ptr(i32* %ptr) #0 {
60 store volatile i32 15, i32* %ptr
64 ; GCN-LABEL: {{^}}func_load_private_arg_i32_ptr:
66 ; GCN-NEXT: buffer_load_dword v0, v0, s[0:3], s4 offen{{$}}
67 define void @func_load_private_arg_i32_ptr(i32* %ptr) #0 {
68 %val = load volatile i32, i32* %ptr
72 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr:
74 ; GCN-NEXT: s_mov_b32 s5, s32
75 ; GCN-NEXT: s_sub_u32 [[SUB_OFFSET:s[0-9]+]], s5, s4
76 ; GCN-NEXT: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], [[SUB_OFFSET]], 6
77 ; GCN-NEXT: v_add_i32_e64 [[ADD:v[0-9]+]], {{s\[[0-9]+:[0-9]+\]}}, 4, [[SHIFT]]
78 ; GCN-NEXT: v_add_i32_e32 v0, vcc, 4, [[ADD]]
80 ; GCN: ds_write_b32 v0, v0
81 define void @void_func_byval_struct_i8_i32_ptr({ i8, i32 }* byval %arg0) #0 {
82 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 0
83 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 1
84 %load1 = load i32, i32* %gep1
85 store volatile i32* %gep1, i32* addrspace(3)* undef
89 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_value:
90 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
91 ; GCN-NEXT: s_mov_b32 s5, s32
92 ; GCN-NEXT: buffer_load_ubyte v0, off, s[0:3], s5
93 ; GCN_NEXT: buffer_load_dword v1, off, s[0:3], s5 offset:4
94 define void @void_func_byval_struct_i8_i32_ptr_value({ i8, i32 }* byval %arg0) #0 {
95 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 0
96 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 1
97 %load0 = load i8, i8* %gep0
98 %load1 = load i32, i32* %gep1
99 store volatile i8 %load0, i8 addrspace(3)* undef
100 store volatile i32 %load1, i32 addrspace(3)* undef
104 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_nonentry_block:
105 ; GCN: s_sub_u32 [[SUB_OFFSET:s[0-9]+]], s5, s4
106 ; GCN: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], [[SUB_OFFSET]], 6
107 ; GCN: v_add_i32_e64 [[ADD:v[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 4, [[SHIFT]]
108 ; GCN: s_and_saveexec_b64
110 ; GCN: v_add_i32_e32 v0, vcc, 4, [[ADD]]
111 ; GCN: buffer_load_dword v1, v1, s[0:3], s4 offen offset:4
113 define void @void_func_byval_struct_i8_i32_ptr_nonentry_block({ i8, i32 }* byval %arg0, i32 %arg2) #0 {
114 %cmp = icmp eq i32 %arg2, 0
115 br i1 %cmp, label %bb, label %ret
118 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 0
119 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 1
120 %load1 = load volatile i32, i32* %gep1
121 store volatile i32* %gep1, i32* addrspace(3)* undef
128 ; Added offset can't be used with VOP3 add
129 ; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32:
130 ; GCN: s_sub_u32 s6, s5, s4
131 ; GCN-DAG: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s6, 6
132 ; GCN-DAG: s_movk_i32 s6, 0x204
133 ; GCN: v_add_i32_e64 v0, s[6:7], s6, [[SCALED]]
134 ; GCN: v_mul_lo_i32 v0, v0, 9
135 ; GCN: ds_write_b32 v0, v0
136 define void @func_other_fi_user_non_inline_imm_offset_i32() #0 {
137 %alloca0 = alloca [128 x i32], align 4
138 %alloca1 = alloca [8 x i32], align 4
139 %gep0 = getelementptr inbounds [128 x i32], [128 x i32]* %alloca0, i32 0, i32 65
140 %gep1 = getelementptr inbounds [8 x i32], [8 x i32]* %alloca1, i32 0, i32 0
141 store volatile i32 7, i32* %gep0
142 %ptrtoint = ptrtoint i32* %gep1 to i32
143 %mul = mul i32 %ptrtoint, 9
144 store volatile i32 %mul, i32 addrspace(3)* undef
148 ; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32_vcc_live:
149 ; GCN: s_sub_u32 [[DIFF:s[0-9]+]], s5, s4
150 ; GCN-DAG: v_lshr_b32_e64 [[SCALED:v[0-9]+]], [[DIFF]], 6
151 ; GCN-DAG: s_movk_i32 [[OFFSET:s[0-9]+]], 0x204
152 ; GCN: v_add_i32_e64 v0, s{{\[[0-9]+:[0-9]+\]}}, [[OFFSET]], [[SCALED]]
153 ; GCN: v_mul_lo_i32 v0, v0, 9
154 ; GCN: ds_write_b32 v0, v0
155 define void @func_other_fi_user_non_inline_imm_offset_i32_vcc_live() #0 {
156 %alloca0 = alloca [128 x i32], align 4
157 %alloca1 = alloca [8 x i32], align 4
158 %vcc = call i64 asm sideeffect "; def $0", "={VCC}"()
159 %gep0 = getelementptr inbounds [128 x i32], [128 x i32]* %alloca0, i32 0, i32 65
160 %gep1 = getelementptr inbounds [8 x i32], [8 x i32]* %alloca1, i32 0, i32 0
161 store volatile i32 7, i32* %gep0
162 call void asm sideeffect "; use $0", "{VCC}"(i64 %vcc)
163 %ptrtoint = ptrtoint i32* %gep1 to i32
164 %mul = mul i32 %ptrtoint, 9
165 store volatile i32 %mul, i32 addrspace(3)* undef
169 declare void @func(<4 x float>* nocapture) #0
171 ; undef flag not preserved in eliminateFrameIndex when handling the
172 ; stores in the middle block.
174 ; GCN-LABEL: {{^}}undefined_stack_store_reg:
175 ; GCN: s_and_saveexec_b64
176 ; GCN: buffer_store_dword v0, off, s[0:3], s5 offset:
177 ; GCN: buffer_store_dword v0, off, s[0:3], s5 offset:
178 ; GCN: buffer_store_dword v0, off, s[0:3], s5 offset:
179 ; GCN: buffer_store_dword v{{[0-9]+}}, off, s[0:3], s5 offset:
180 define void @undefined_stack_store_reg(float %arg, i32 %arg1) #0 {
182 %tmp = alloca <4 x float>, align 16
183 %tmp2 = insertelement <4 x float> undef, float %arg, i32 0
184 store <4 x float> %tmp2, <4 x float>* undef
185 %tmp3 = icmp eq i32 %arg1, 0
186 br i1 %tmp3, label %bb4, label %bb5
189 call void @func(<4 x float>* nonnull undef)
190 store <4 x float> %tmp2, <4 x float>* %tmp, align 16
191 call void @func(<4 x float>* nonnull %tmp)
198 attributes #0 = { nounwind }