blob: 9bc46434d59e4976fc6409cf07853d35ebc8a450 [file] [log] [blame]
Matt Arsenault8728c5f2017-08-07 14:58:04 +00001; 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
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +00002
3; Test that non-entry function frame indices are expanded properly to
4; give an index relative to the scratch wave offset register
5
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)
Matthias Braun7a482e22017-06-20 18:43:14 +00009; 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]]
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +000012; GCN-NOT: v_mov
13; GCN: ds_write_b32 v0, v0
14define void @func_mov_fi_i32() #0 {
15 %alloca = alloca i32
16 store volatile i32* %alloca, i32* addrspace(3)* undef
17 ret void
18}
19
20; Materialize into an add of a constant offset from the FI.
21; FIXME: Should be able to merge adds
22
23; GCN-LABEL: {{^}}func_add_constant_to_fi_i32:
24; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
Matthias Braun7a482e22017-06-20 18:43:14 +000025; 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]]
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +000028; GCN-NEXT: v_add_i32_e32 v0, vcc, 4, v0
29; GCN-NOT: v_mov
30; GCN: ds_write_b32 v0, v0
31define 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
35 ret void
36}
37
38; A user the materialized frame index can't be meaningfully folded
39; into.
40
41; GCN-LABEL: {{^}}func_other_fi_user_i32:
Matthias Braun7a482e22017-06-20 18:43:14 +000042; 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]]
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +000045; GCN-NEXT: v_mul_lo_i32 v0, v0, 9
46; GCN-NOT: v_mov
47; GCN: ds_write_b32 v0, v0
48define 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
53 ret void
54}
55
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{{$}}
59define void @func_store_private_arg_i32_ptr(i32* %ptr) #0 {
60 store volatile i32 15, i32* %ptr
61 ret void
62}
63
64; GCN-LABEL: {{^}}func_load_private_arg_i32_ptr:
65; GCN: s_waitcnt
66; GCN-NEXT: buffer_load_dword v0, v0, s[0:3], s4 offen{{$}}
67define void @func_load_private_arg_i32_ptr(i32* %ptr) #0 {
68 %val = load volatile i32, i32* %ptr
69 ret void
70}
71
72; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr:
73; GCN: s_waitcnt
Matt Arsenaultf28683c2017-06-26 17:53:59 +000074; GCN-NEXT: s_mov_b32 s5, s32
Matt Arsenaultd1867c02017-08-02 00:59:51 +000075; 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]]
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +000079; GCN-NOT: v_mov
80; GCN: ds_write_b32 v0, v0
81define 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
86 ret void
87}
88
89; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_value:
90; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
Matt Arsenaultf28683c2017-06-26 17:53:59 +000091; GCN-NEXT: s_mov_b32 s5, s32
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +000092; 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
94define 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
101 ret void
102}
103
Matt Arsenault45b98182017-11-15 00:45:43 +0000104; FIXME: Should be able to see that this can use vaddr, but the
105; FrameIndex is hidden behind a CopyFromReg in the second block.
106
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000107; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_nonentry_block:
Matt Arsenaultd1867c02017-08-02 00:59:51 +0000108; GCN: s_sub_u32 [[SUB_OFFSET:s[0-9]+]], s5, s4
109; GCN: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], [[SUB_OFFSET]], 6
110; GCN: v_add_i32_e64 [[ADD:v[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 4, [[SHIFT]]
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000111; GCN: s_and_saveexec_b64
112
Matt Arsenaultd1867c02017-08-02 00:59:51 +0000113; GCN: v_add_i32_e32 v0, vcc, 4, [[ADD]]
Matt Arsenault45b98182017-11-15 00:45:43 +0000114; GCN: buffer_load_dword v1, v0, s[0:3], s4 offen{{$}}
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000115; GCN: ds_write_b32
116define void @void_func_byval_struct_i8_i32_ptr_nonentry_block({ i8, i32 }* byval %arg0, i32 %arg2) #0 {
117 %cmp = icmp eq i32 %arg2, 0
118 br i1 %cmp, label %bb, label %ret
119
120bb:
121 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 0
122 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %arg0, i32 0, i32 1
123 %load1 = load volatile i32, i32* %gep1
124 store volatile i32* %gep1, i32* addrspace(3)* undef
125 br label %ret
126
127ret:
128 ret void
129}
130
Matt Arsenaultc5951852017-06-19 23:47:21 +0000131; Added offset can't be used with VOP3 add
132; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32:
Matthias Braun7a482e22017-06-20 18:43:14 +0000133; GCN: s_sub_u32 s6, s5, s4
134; GCN-DAG: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s6, 6
135; GCN-DAG: s_movk_i32 s6, 0x204
136; GCN: v_add_i32_e64 v0, s[6:7], s6, [[SCALED]]
Matt Arsenaultc5951852017-06-19 23:47:21 +0000137; GCN: v_mul_lo_i32 v0, v0, 9
138; GCN: ds_write_b32 v0, v0
139define void @func_other_fi_user_non_inline_imm_offset_i32() #0 {
140 %alloca0 = alloca [128 x i32], align 4
141 %alloca1 = alloca [8 x i32], align 4
142 %gep0 = getelementptr inbounds [128 x i32], [128 x i32]* %alloca0, i32 0, i32 65
143 %gep1 = getelementptr inbounds [8 x i32], [8 x i32]* %alloca1, i32 0, i32 0
144 store volatile i32 7, i32* %gep0
145 %ptrtoint = ptrtoint i32* %gep1 to i32
146 %mul = mul i32 %ptrtoint, 9
147 store volatile i32 %mul, i32 addrspace(3)* undef
148 ret void
149}
Matt Arsenaulta2025382017-08-03 23:24:05 +0000150
Matt Arsenaultc5951852017-06-19 23:47:21 +0000151; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32_vcc_live:
152; GCN: s_sub_u32 [[DIFF:s[0-9]+]], s5, s4
153; GCN-DAG: v_lshr_b32_e64 [[SCALED:v[0-9]+]], [[DIFF]], 6
154; GCN-DAG: s_movk_i32 [[OFFSET:s[0-9]+]], 0x204
155; GCN: v_add_i32_e64 v0, s{{\[[0-9]+:[0-9]+\]}}, [[OFFSET]], [[SCALED]]
156; GCN: v_mul_lo_i32 v0, v0, 9
157; GCN: ds_write_b32 v0, v0
158define void @func_other_fi_user_non_inline_imm_offset_i32_vcc_live() #0 {
159 %alloca0 = alloca [128 x i32], align 4
160 %alloca1 = alloca [8 x i32], align 4
161 %vcc = call i64 asm sideeffect "; def $0", "={VCC}"()
162 %gep0 = getelementptr inbounds [128 x i32], [128 x i32]* %alloca0, i32 0, i32 65
163 %gep1 = getelementptr inbounds [8 x i32], [8 x i32]* %alloca1, i32 0, i32 0
164 store volatile i32 7, i32* %gep0
165 call void asm sideeffect "; use $0", "{VCC}"(i64 %vcc)
166 %ptrtoint = ptrtoint i32* %gep1 to i32
167 %mul = mul i32 %ptrtoint, 9
168 store volatile i32 %mul, i32 addrspace(3)* undef
169 ret void
170}
171
Matt Arsenaulta5fcb832017-08-01 19:54:58 +0000172declare void @func(<4 x float>* nocapture) #0
173
174; undef flag not preserved in eliminateFrameIndex when handling the
175; stores in the middle block.
176
177; GCN-LABEL: {{^}}undefined_stack_store_reg:
178; GCN: s_and_saveexec_b64
179; GCN: buffer_store_dword v0, off, s[0:3], s5 offset:
180; GCN: buffer_store_dword v0, off, s[0:3], s5 offset:
181; GCN: buffer_store_dword v0, off, s[0:3], s5 offset:
182; GCN: buffer_store_dword v{{[0-9]+}}, off, s[0:3], s5 offset:
183define void @undefined_stack_store_reg(float %arg, i32 %arg1) #0 {
184bb:
185 %tmp = alloca <4 x float>, align 16
186 %tmp2 = insertelement <4 x float> undef, float %arg, i32 0
187 store <4 x float> %tmp2, <4 x float>* undef
188 %tmp3 = icmp eq i32 %arg1, 0
189 br i1 %tmp3, label %bb4, label %bb5
190
191bb4:
192 call void @func(<4 x float>* nonnull undef)
193 store <4 x float> %tmp2, <4 x float>* %tmp, align 16
194 call void @func(<4 x float>* nonnull %tmp)
195 br label %bb5
196
197bb5:
198 ret void
199}
200
Matt Arsenault45b98182017-11-15 00:45:43 +0000201; GCN-LABEL: {{^}}alloca_ptr_nonentry_block:
202; GCN: s_and_saveexec_b64
203; GCN: buffer_load_dword v{{[0-9]+}}, off, s[0:3], s5 offset:12
204define void @alloca_ptr_nonentry_block(i32 %arg0) #0 {
205 %alloca0 = alloca { i8, i32 }, align 4
206 %cmp = icmp eq i32 %arg0, 0
207 br i1 %cmp, label %bb, label %ret
208
209bb:
210 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %alloca0, i32 0, i32 0
211 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 }* %alloca0, i32 0, i32 1
212 %load1 = load volatile i32, i32* %gep1
213 store volatile i32* %gep1, i32* addrspace(3)* undef
214 br label %ret
215
216ret:
217 ret void
218}
219
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000220attributes #0 = { nounwind }