blob: b98428a49fb0d8339f248b41f8a128a43424f745 [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
104; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_nonentry_block:
Matt Arsenaultd1867c02017-08-02 00:59:51 +0000105; 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]]
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000108; GCN: s_and_saveexec_b64
109
Matt Arsenaultd1867c02017-08-02 00:59:51 +0000110; GCN: v_add_i32_e32 v0, vcc, 4, [[ADD]]
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000111; GCN: buffer_load_dword v1, v1, s[0:3], s4 offen offset:4
112; GCN: ds_write_b32
113define 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
116
117bb:
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
122 br label %ret
123
124ret:
125 ret void
126}
127
Matt Arsenaultc5951852017-06-19 23:47:21 +0000128; Added offset can't be used with VOP3 add
129; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32:
Matthias Braun7a482e22017-06-20 18:43:14 +0000130; 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]]
Matt Arsenaultc5951852017-06-19 23:47:21 +0000134; GCN: v_mul_lo_i32 v0, v0, 9
135; GCN: ds_write_b32 v0, v0
136define 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
145 ret void
146}
Matt Arsenaulta2025382017-08-03 23:24:05 +0000147
Matt Arsenaultc5951852017-06-19 23:47:21 +0000148; 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
155define 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
166 ret void
167}
168
Matt Arsenaulta5fcb832017-08-01 19:54:58 +0000169declare void @func(<4 x float>* nocapture) #0
170
171; undef flag not preserved in eliminateFrameIndex when handling the
172; stores in the middle block.
173
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:
180define void @undefined_stack_store_reg(float %arg, i32 %arg1) #0 {
181bb:
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
187
188bb4:
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)
192 br label %bb5
193
194bb5:
195 ret void
196}
197
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000198attributes #0 = { nounwind }