1 ; RUN: opt -S -march=r600 -mcpu=cayman -basic-aa -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine < %s | FileCheck %s
3 ; Check vectorization that would ordinarily require a runtime bounds
4 ; check on the pointers when mixing address spaces. For now we cannot
5 ; assume address spaces do not alias, and we can't assume that
6 ; different pointers are directly comparable.
8 ; These all test this basic loop for different combinations of address
9 ; spaces, and swapping in globals or adding noalias.
11 ;void foo(int addrspace(N)* [noalias] a, int addrspace(M)* [noalias] b, int n)
13 ; for (int i = 0; i < n; ++i)
19 ; Artificial datalayout
20 target datalayout = "e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-v2048:2048:2048-n32:64"
23 @g_as1 = common addrspace(1) global [1024 x i32] zeroinitializer, align 16
24 @q_as2 = common addrspace(2) global [1024 x i32] zeroinitializer, align 16
26 ; Both parameters are unidentified objects with the same address
27 ; space, so this should vectorize normally.
28 define void @foo(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 %n) #0 {
34 %cmp1 = icmp slt i32 0, %n
35 br i1 %cmp1, label %for.body, label %for.end
37 for.body: ; preds = %entry, %for.body
38 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
39 %idxprom = sext i32 %i.02 to i64
40 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom
41 %0 = load i32, i32 addrspace(1)* %arrayidx, align 4
42 %mul = mul nsw i32 %0, 3
43 %idxprom1 = sext i32 %i.02 to i64
44 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %idxprom1
45 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
46 %inc = add nsw i32 %i.02, 1
47 %cmp = icmp slt i32 %inc, %n
48 br i1 %cmp, label %for.body, label %for.end
50 for.end: ; preds = %for.body, %entry
54 ; Parameters are unidentified and different address spaces, so cannot vectorize.
55 define void @bar0(i32* %a, i32 addrspace(1)* %b, i32 %n) #0 {
57 ; CHECK-NOT: <4 x i32>
61 %cmp1 = icmp slt i32 0, %n
62 br i1 %cmp1, label %for.body, label %for.end
64 for.body: ; preds = %entry, %for.body
65 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
66 %idxprom = sext i32 %i.02 to i64
67 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom
68 %0 = load i32, i32 addrspace(1)* %arrayidx, align 4
69 %mul = mul nsw i32 %0, 3
70 %idxprom1 = sext i32 %i.02 to i64
71 %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1
72 store i32 %mul, i32* %arrayidx2, align 4
73 %inc = add nsw i32 %i.02, 1
74 %cmp = icmp slt i32 %inc, %n
75 br i1 %cmp, label %for.body, label %for.end
77 for.end: ; preds = %for.body, %entry
81 ; Swapped arguments should be the same
82 define void @bar1(i32 addrspace(1)* %a, i32* %b, i32 %n) #0 {
84 ; CHECK-NOT: <4 x i32>
88 %cmp1 = icmp slt i32 0, %n
89 br i1 %cmp1, label %for.body, label %for.end
91 for.body: ; preds = %entry, %for.body
92 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
93 %idxprom = sext i32 %i.02 to i64
94 %arrayidx = getelementptr inbounds i32, i32* %b, i64 %idxprom
95 %0 = load i32, i32* %arrayidx, align 4
96 %mul = mul nsw i32 %0, 3
97 %idxprom1 = sext i32 %i.02 to i64
98 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %idxprom1
99 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
100 %inc = add nsw i32 %i.02, 1
101 %cmp = icmp slt i32 %inc, %n
102 br i1 %cmp, label %for.body, label %for.end
104 for.end: ; preds = %for.body, %entry
108 ; We should still be able to vectorize with noalias even if the
109 ; address spaces are different.
110 define void @bar2(i32* noalias %a, i32 addrspace(1)* noalias %b, i32 %n) #0 {
111 ; CHECK-LABEL: @bar2(
116 %cmp1 = icmp slt i32 0, %n
117 br i1 %cmp1, label %for.body, label %for.end
119 for.body: ; preds = %entry, %for.body
120 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
121 %idxprom = sext i32 %i.02 to i64
122 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom
123 %0 = load i32, i32 addrspace(1)* %arrayidx, align 4
124 %mul = mul nsw i32 %0, 3
125 %idxprom1 = sext i32 %i.02 to i64
126 %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1
127 store i32 %mul, i32* %arrayidx2, align 4
128 %inc = add nsw i32 %i.02, 1
129 %cmp = icmp slt i32 %inc, %n
130 br i1 %cmp, label %for.body, label %for.end
132 for.end: ; preds = %for.body, %entry
136 ; Store to identified global with different address space. This isn't
137 ; generally safe and shouldn't be vectorized.
138 define void @arst0(i32* %b, i32 %n) #0 {
139 ; CHECK-LABEL: @arst0(
140 ; CHECK-NOT: <4 x i32>
144 %cmp1 = icmp slt i32 0, %n
145 br i1 %cmp1, label %for.body, label %for.end
147 for.body: ; preds = %entry, %for.body
148 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
149 %idxprom = sext i32 %i.02 to i64
150 %arrayidx = getelementptr inbounds i32, i32* %b, i64 %idxprom
151 %0 = load i32, i32* %arrayidx, align 4
152 %mul = mul nsw i32 %0, 3
153 %idxprom1 = sext i32 %i.02 to i64
154 %arrayidx2 = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom1
155 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
156 %inc = add nsw i32 %i.02, 1
157 %cmp = icmp slt i32 %inc, %n
158 br i1 %cmp, label %for.body, label %for.end
160 for.end: ; preds = %for.body, %entry
165 ; Load from identified global with different address space.
166 ; This isn't generally safe and shouldn't be vectorized.
167 define void @arst1(i32* %b, i32 %n) #0 {
168 ; CHECK-LABEL: @arst1(
169 ; CHECK-NOT: <4 x i32>
173 %cmp1 = icmp slt i32 0, %n
174 br i1 %cmp1, label %for.body, label %for.end
176 for.body: ; preds = %entry, %for.body
177 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
178 %idxprom = sext i32 %i.02 to i64
179 %arrayidx = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom
180 %0 = load i32, i32 addrspace(1)* %arrayidx, align 4
181 %mul = mul nsw i32 %0, 3
182 %idxprom1 = sext i32 %i.02 to i64
183 %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %idxprom1
184 store i32 %mul, i32* %arrayidx2, align 4
185 %inc = add nsw i32 %i.02, 1
186 %cmp = icmp slt i32 %inc, %n
187 br i1 %cmp, label %for.body, label %for.end
189 for.end: ; preds = %for.body, %entry
193 ; Read and write to 2 identified globals in different address
194 ; spaces. This should be vectorized.
195 define void @aoeu(i32 %n) #0 {
196 ; CHECK-LABEL: @aoeu(
201 %cmp1 = icmp slt i32 0, %n
202 br i1 %cmp1, label %for.body, label %for.end
204 for.body: ; preds = %entry, %for.body
205 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
206 %idxprom = sext i32 %i.02 to i64
207 %arrayidx = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(2)* @q_as2, i64 0, i64 %idxprom
208 %0 = load i32, i32 addrspace(2)* %arrayidx, align 4
209 %mul = mul nsw i32 %0, 3
210 %idxprom1 = sext i32 %i.02 to i64
211 %arrayidx2 = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom1
212 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
213 %inc = add nsw i32 %i.02, 1
214 %cmp = icmp slt i32 %inc, %n
215 br i1 %cmp, label %for.body, label %for.end
217 for.end: ; preds = %for.body, %entry
221 attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }