[LoopVectorizer] Refine loop vectorizer's register usage calculator by ignoring speci...
[oota-llvm.git] / test / Transforms / LoopVectorize / runtime-check-address-space.ll
1 ; RUN: opt -S -march=r600 -mcpu=cayman -basicaa -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine < %s | FileCheck %s
2
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.
7 ;
8 ; These all test this basic loop for different combinations of address
9 ; spaces, and swapping in globals or adding noalias.
10 ;
11 ;void foo(int addrspace(N)* [noalias] a, int addrspace(M)* [noalias] b, int n)
12 ;{
13 ;    for (int i = 0; i < n; ++i)
14 ;    {
15 ;        a[i] = 3 * b[i];
16 ;    }
17 ;}
18
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"
21
22
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
25
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 {
29 ; CHECK-LABEL: @foo(
30 ; CHECK: <4 x i32>
31 ; CHECK: ret
32
33 entry:
34   %cmp1 = icmp slt i32 0, %n
35   br i1 %cmp1, label %for.body, label %for.end
36
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
49
50 for.end:                                          ; preds = %for.body, %entry
51   ret void
52 }
53
54 ; Parameters are unidentified and different address spaces, so cannot vectorize.
55 define void @bar0(i32* %a, i32 addrspace(1)* %b, i32 %n) #0 {
56 ; CHECK-LABEL: @bar0(
57 ; CHECK-NOT: <4 x i32>
58 ; CHECK: ret
59
60 entry:
61   %cmp1 = icmp slt i32 0, %n
62   br i1 %cmp1, label %for.body, label %for.end
63
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
76
77 for.end:                                          ; preds = %for.body, %entry
78   ret void
79 }
80
81 ; Swapped arguments should be the same
82 define void @bar1(i32 addrspace(1)* %a, i32* %b, i32 %n) #0 {
83 ; CHECK-LABEL: @bar1(
84 ; CHECK-NOT: <4 x i32>
85 ; CHECK: ret
86
87 entry:
88   %cmp1 = icmp slt i32 0, %n
89   br i1 %cmp1, label %for.body, label %for.end
90
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
103
104 for.end:                                          ; preds = %for.body, %entry
105   ret void
106 }
107
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(
112 ; CHECK: <4 x i32>
113 ; CHECK: ret
114
115 entry:
116   %cmp1 = icmp slt i32 0, %n
117   br i1 %cmp1, label %for.body, label %for.end
118
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
131
132 for.end:                                          ; preds = %for.body, %entry
133   ret void
134 }
135
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>
141 ; CHECK: ret
142
143 entry:
144   %cmp1 = icmp slt i32 0, %n
145   br i1 %cmp1, label %for.body, label %for.end
146
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
159
160 for.end:                                          ; preds = %for.body, %entry
161   ret void
162 }
163
164
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>
170 ; CHECK: ret
171
172 entry:
173   %cmp1 = icmp slt i32 0, %n
174   br i1 %cmp1, label %for.body, label %for.end
175
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
188
189 for.end:                                          ; preds = %for.body, %entry
190   ret void
191 }
192
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(
197 ; CHECK: <4 x i32>
198 ; CHECK: ret
199
200 entry:
201   %cmp1 = icmp slt i32 0, %n
202   br i1 %cmp1, label %for.body, label %for.end
203
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
216
217 for.end:                                          ; preds = %for.body, %entry
218   ret void
219 }
220
221 attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }