1 ; RUN: opt -S -load-store-vectorizer --mcpu=hawaii -mattr=-unaligned-access-mode,+max-private-element-size-16 < %s | FileCheck -check-prefix=ALIGNED -check-prefix=ALL %s
2 ; RUN: opt -S -load-store-vectorizer --mcpu=hawaii -mattr=+unaligned-access-mode,+unaligned-scratch-access,+max-private-element-size-16 < %s | FileCheck -check-prefix=UNALIGNED -check-prefix=ALL %s
3 ; RUN: opt -S -passes='function(load-store-vectorizer)' --mcpu=hawaii -mattr=-unaligned-access-mode,+max-private-element-size-16 < %s | FileCheck -check-prefix=ALIGNED -check-prefix=ALL %s
4 ; RUN: opt -S -passes='function(load-store-vectorizer)' --mcpu=hawaii -mattr=+unaligned-access-mode,+unaligned-scratch-access,+max-private-element-size-16 < %s | FileCheck -check-prefix=UNALIGNED -check-prefix=ALL %s
6 target triple = "amdgcn--"
7 target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
9 ; ALL-LABEL: @load_unknown_offset_align1_i8(
10 ; ALL: alloca [128 x i8], align 1
11 ; UNALIGNED: load <2 x i8>, <2 x i8> addrspace(5)* %{{[0-9]+}}, align 1{{$}}
12 define amdgpu_kernel void @load_unknown_offset_align1_i8(i8 addrspace(1)* noalias %out, i32 %offset) #0 {
13 %alloca = alloca [128 x i8], align 1, addrspace(5)
14 %ptr0 = getelementptr inbounds [128 x i8], [128 x i8] addrspace(5)* %alloca, i32 0, i32 %offset
15 %val0 = load i8, i8 addrspace(5)* %ptr0, align 1
16 %ptr1 = getelementptr inbounds i8, i8 addrspace(5)* %ptr0, i32 1
17 %val1 = load i8, i8 addrspace(5)* %ptr1, align 1
18 %add = add i8 %val0, %val1
19 store i8 %add, i8 addrspace(1)* %out
23 ; ALL-LABEL: @load_unknown_offset_align1_i16(
24 ; ALL: alloca [128 x i16], align 1, addrspace(5){{$}}
25 ; UNALIGNED: load <2 x i16>, <2 x i16> addrspace(5)* %{{[0-9]+}}, align 1{{$}}
27 ; ALIGNED: load i16, i16 addrspace(5)* %ptr0, align 1{{$}}
28 ; ALIGNED: load i16, i16 addrspace(5)* %ptr1, align 1{{$}}
29 define amdgpu_kernel void @load_unknown_offset_align1_i16(i16 addrspace(1)* noalias %out, i32 %offset) #0 {
30 %alloca = alloca [128 x i16], align 1, addrspace(5)
31 %ptr0 = getelementptr inbounds [128 x i16], [128 x i16] addrspace(5)* %alloca, i32 0, i32 %offset
32 %val0 = load i16, i16 addrspace(5)* %ptr0, align 1
33 %ptr1 = getelementptr inbounds i16, i16 addrspace(5)* %ptr0, i32 1
34 %val1 = load i16, i16 addrspace(5)* %ptr1, align 1
35 %add = add i16 %val0, %val1
36 store i16 %add, i16 addrspace(1)* %out
40 ; FIXME: Although the offset is unknown here, we know it is a multiple
41 ; of the element size, so should still be align 4
43 ; ALL-LABEL: @load_unknown_offset_align1_i32(
44 ; ALL: alloca [128 x i32], align 1
45 ; UNALIGNED: load <2 x i32>, <2 x i32> addrspace(5)* %{{[0-9]+}}, align 1{{$}}
47 ; ALIGNED: load i32, i32 addrspace(5)* %ptr0, align 1
48 ; ALIGNED: load i32, i32 addrspace(5)* %ptr1, align 1
49 define amdgpu_kernel void @load_unknown_offset_align1_i32(i32 addrspace(1)* noalias %out, i32 %offset) #0 {
50 %alloca = alloca [128 x i32], align 1, addrspace(5)
51 %ptr0 = getelementptr inbounds [128 x i32], [128 x i32] addrspace(5)* %alloca, i32 0, i32 %offset
52 %val0 = load i32, i32 addrspace(5)* %ptr0, align 1
53 %ptr1 = getelementptr inbounds i32, i32 addrspace(5)* %ptr0, i32 1
54 %val1 = load i32, i32 addrspace(5)* %ptr1, align 1
55 %add = add i32 %val0, %val1
56 store i32 %add, i32 addrspace(1)* %out
60 ; Make sure alloca alignment isn't decreased
61 ; ALL-LABEL: @load_alloca16_unknown_offset_align1_i32(
62 ; ALL: alloca [128 x i32], align 16
64 ; ALL: load <2 x i32>, <2 x i32> addrspace(5)* %{{[0-9]+}}, align 4{{$}}
65 define amdgpu_kernel void @load_alloca16_unknown_offset_align1_i32(i32 addrspace(1)* noalias %out, i32 %offset) #0 {
66 %alloca = alloca [128 x i32], align 16, addrspace(5)
67 %ptr0 = getelementptr inbounds [128 x i32], [128 x i32] addrspace(5)* %alloca, i32 0, i32 %offset
68 %val0 = load i32, i32 addrspace(5)* %ptr0, align 1
69 %ptr1 = getelementptr inbounds i32, i32 addrspace(5)* %ptr0, i32 1
70 %val1 = load i32, i32 addrspace(5)* %ptr1, align 1
71 %add = add i32 %val0, %val1
72 store i32 %add, i32 addrspace(1)* %out
76 ; ALL-LABEL: @store_unknown_offset_align1_i8(
77 ; ALL: alloca [128 x i8], align 1
78 ; UNALIGNED: store <2 x i8> <i8 9, i8 10>, <2 x i8> addrspace(5)* %{{[0-9]+}}, align 1{{$}}
80 ; ALIGNED: store i8 9, i8 addrspace(5)* %ptr0, align 1{{$}}
81 ; ALIGNED: store i8 10, i8 addrspace(5)* %ptr1, align 1{{$}}
82 define amdgpu_kernel void @store_unknown_offset_align1_i8(i8 addrspace(1)* noalias %out, i32 %offset) #0 {
83 %alloca = alloca [128 x i8], align 1, addrspace(5)
84 %ptr0 = getelementptr inbounds [128 x i8], [128 x i8] addrspace(5)* %alloca, i32 0, i32 %offset
85 store i8 9, i8 addrspace(5)* %ptr0, align 1
86 %ptr1 = getelementptr inbounds i8, i8 addrspace(5)* %ptr0, i32 1
87 store i8 10, i8 addrspace(5)* %ptr1, align 1
91 ; ALL-LABEL: @store_unknown_offset_align1_i16(
92 ; ALL: alloca [128 x i16], align 1
93 ; UNALIGNED: store <2 x i16> <i16 9, i16 10>, <2 x i16> addrspace(5)* %{{[0-9]+}}, align 1{{$}}
95 ; ALIGNED: store i16 9, i16 addrspace(5)* %ptr0, align 1{{$}}
96 ; ALIGNED: store i16 10, i16 addrspace(5)* %ptr1, align 1{{$}}
97 define amdgpu_kernel void @store_unknown_offset_align1_i16(i16 addrspace(1)* noalias %out, i32 %offset) #0 {
98 %alloca = alloca [128 x i16], align 1, addrspace(5)
99 %ptr0 = getelementptr inbounds [128 x i16], [128 x i16] addrspace(5)* %alloca, i32 0, i32 %offset
100 store i16 9, i16 addrspace(5)* %ptr0, align 1
101 %ptr1 = getelementptr inbounds i16, i16 addrspace(5)* %ptr0, i32 1
102 store i16 10, i16 addrspace(5)* %ptr1, align 1
106 ; FIXME: Although the offset is unknown here, we know it is a multiple
107 ; of the element size, so it still should be align 4.
109 ; ALL-LABEL: @store_unknown_offset_align1_i32(
110 ; ALL: alloca [128 x i32], align 1
112 ; UNALIGNED: store <2 x i32> <i32 9, i32 10>, <2 x i32> addrspace(5)* %{{[0-9]+}}, align 1{{$}}
114 ; ALIGNED: store i32 9, i32 addrspace(5)* %ptr0, align 1
115 ; ALIGNED: store i32 10, i32 addrspace(5)* %ptr1, align 1
116 define amdgpu_kernel void @store_unknown_offset_align1_i32(i32 addrspace(1)* noalias %out, i32 %offset) #0 {
117 %alloca = alloca [128 x i32], align 1, addrspace(5)
118 %ptr0 = getelementptr inbounds [128 x i32], [128 x i32] addrspace(5)* %alloca, i32 0, i32 %offset
119 store i32 9, i32 addrspace(5)* %ptr0, align 1
120 %ptr1 = getelementptr inbounds i32, i32 addrspace(5)* %ptr0, i32 1
121 store i32 10, i32 addrspace(5)* %ptr1, align 1
125 ; ALL-LABEL: @merge_private_store_4_vector_elts_loads_v4i32(
126 ; ALL: %alloca = alloca [8 x i32], align 4, addrspace(5)
127 ; ALL: store <4 x i32> <i32 9, i32 1, i32 23, i32 19>, <4 x i32> addrspace(5)* %1, align 4
128 define amdgpu_kernel void @merge_private_store_4_vector_elts_loads_v4i32() {
129 %alloca = alloca [8 x i32], align 1, addrspace(5)
130 %out = bitcast [8 x i32] addrspace(5)* %alloca to i32 addrspace(5)*
131 %out.gep.1 = getelementptr i32, i32 addrspace(5)* %out, i32 1
132 %out.gep.2 = getelementptr i32, i32 addrspace(5)* %out, i32 2
133 %out.gep.3 = getelementptr i32, i32 addrspace(5)* %out, i32 3
135 store i32 9, i32 addrspace(5)* %out, align 1
136 store i32 1, i32 addrspace(5)* %out.gep.1, align 1
137 store i32 23, i32 addrspace(5)* %out.gep.2, align 1
138 store i32 19, i32 addrspace(5)* %out.gep.3, align 1
142 ; ALL-LABEL: @merge_private_store_4_vector_elts_loads_v4i8(
143 ; ALL: %alloca = alloca [8 x i8], align 4, addrspace(5)
144 ; ALL: store <4 x i8> <i8 9, i8 1, i8 23, i8 19>, <4 x i8> addrspace(5)* %1, align 4
145 define amdgpu_kernel void @merge_private_store_4_vector_elts_loads_v4i8() {
146 %alloca = alloca [8 x i8], align 1, addrspace(5)
147 %out = bitcast [8 x i8] addrspace(5)* %alloca to i8 addrspace(5)*
148 %out.gep.1 = getelementptr i8, i8 addrspace(5)* %out, i8 1
149 %out.gep.2 = getelementptr i8, i8 addrspace(5)* %out, i8 2
150 %out.gep.3 = getelementptr i8, i8 addrspace(5)* %out, i8 3
152 store i8 9, i8 addrspace(5)* %out, align 1
153 store i8 1, i8 addrspace(5)* %out.gep.1, align 1
154 store i8 23, i8 addrspace(5)* %out.gep.2, align 1
155 store i8 19, i8 addrspace(5)* %out.gep.3, align 1
159 ; ALL-LABEL: @merge_private_load_4_vector_elts_loads_v4i32(
160 ; ALL: %alloca = alloca [8 x i32], align 4, addrspace(5)
161 ; ALL: load <4 x i32>, <4 x i32> addrspace(5)* %1, align 4
162 define amdgpu_kernel void @merge_private_load_4_vector_elts_loads_v4i32() {
163 %alloca = alloca [8 x i32], align 1, addrspace(5)
164 %out = bitcast [8 x i32] addrspace(5)* %alloca to i32 addrspace(5)*
165 %out.gep.1 = getelementptr i32, i32 addrspace(5)* %out, i32 1
166 %out.gep.2 = getelementptr i32, i32 addrspace(5)* %out, i32 2
167 %out.gep.3 = getelementptr i32, i32 addrspace(5)* %out, i32 3
169 %load0 = load i32, i32 addrspace(5)* %out, align 1
170 %load1 = load i32, i32 addrspace(5)* %out.gep.1, align 1
171 %load2 = load i32, i32 addrspace(5)* %out.gep.2, align 1
172 %load3 = load i32, i32 addrspace(5)* %out.gep.3, align 1
176 ; ALL-LABEL: @merge_private_load_4_vector_elts_loads_v4i8(
177 ; ALL: %alloca = alloca [8 x i8], align 4, addrspace(5)
178 ; ALL: load <4 x i8>, <4 x i8> addrspace(5)* %1, align 4
179 define amdgpu_kernel void @merge_private_load_4_vector_elts_loads_v4i8() {
180 %alloca = alloca [8 x i8], align 1, addrspace(5)
181 %out = bitcast [8 x i8] addrspace(5)* %alloca to i8 addrspace(5)*
182 %out.gep.1 = getelementptr i8, i8 addrspace(5)* %out, i8 1
183 %out.gep.2 = getelementptr i8, i8 addrspace(5)* %out, i8 2
184 %out.gep.3 = getelementptr i8, i8 addrspace(5)* %out, i8 3
186 %load0 = load i8, i8 addrspace(5)* %out, align 1
187 %load1 = load i8, i8 addrspace(5)* %out.gep.1, align 1
188 %load2 = load i8, i8 addrspace(5)* %out.gep.2, align 1
189 %load3 = load i8, i8 addrspace(5)* %out.gep.3, align 1
193 ; Make sure we don't think the alignment will increase if the base address isn't an alloca
194 ; ALL-LABEL: @private_store_2xi16_align2_not_alloca(
197 define void @private_store_2xi16_align2_not_alloca(i16 addrspace(5)* %p, i16 addrspace(5)* %r) #0 {
198 %gep.r = getelementptr i16, i16 addrspace(5)* %r, i32 1
199 store i16 1, i16 addrspace(5)* %r, align 2
200 store i16 2, i16 addrspace(5)* %gep.r, align 2
204 ; ALL-LABEL: @private_store_2xi16_align1_not_alloca(
207 ; UNALIGNED: store <2 x i16>
208 define void @private_store_2xi16_align1_not_alloca(i16 addrspace(5)* %p, i16 addrspace(5)* %r) #0 {
209 %gep.r = getelementptr i16, i16 addrspace(5)* %r, i32 1
210 store i16 1, i16 addrspace(5)* %r, align 1
211 store i16 2, i16 addrspace(5)* %gep.r, align 1
215 ; ALL-LABEL: @private_load_2xi16_align2_not_alloca(
218 define i32 @private_load_2xi16_align2_not_alloca(i16 addrspace(5)* %p) #0 {
219 %gep.p = getelementptr i16, i16 addrspace(5)* %p, i64 1
220 %p.0 = load i16, i16 addrspace(5)* %p, align 2
221 %p.1 = load i16, i16 addrspace(5)* %gep.p, align 2
222 %zext.0 = zext i16 %p.0 to i32
223 %zext.1 = zext i16 %p.1 to i32
224 %shl.1 = shl i32 %zext.1, 16
225 %or = or i32 %zext.0, %shl.1
229 ; ALL-LABEL: @private_load_2xi16_align1_not_alloca(
232 ; UNALIGNED: load <2 x i16>
233 define i32 @private_load_2xi16_align1_not_alloca(i16 addrspace(5)* %p) #0 {
234 %gep.p = getelementptr i16, i16 addrspace(5)* %p, i64 1
235 %p.0 = load i16, i16 addrspace(5)* %p, align 1
236 %p.1 = load i16, i16 addrspace(5)* %gep.p, align 1
237 %zext.0 = zext i16 %p.0 to i32
238 %zext.1 = zext i16 %p.1 to i32
239 %shl.1 = shl i32 %zext.1, 16
240 %or = or i32 %zext.0, %shl.1
244 attributes #0 = { nounwind }