blob: 1d3364771722f853ffab93a390572cb79846540f [file] [log] [blame]
Sanjay Patelb653de12014-09-10 17:58:16 +00001; RUN: opt -S -march=r600 -mcpu=cayman -basicaa -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine < %s | FileCheck %s
Matt Arsenault0be1cb12013-10-02 22:38:17 +00002
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
20target 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.
28define 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
33entry:
Michael Zolotukhin540580c2014-12-02 22:59:02 +000034 %cmp1 = icmp slt i32 0, %n
35 br i1 %cmp1, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +000036
Michael Zolotukhin540580c2014-12-02 22:59:02 +000037for.body: ; preds = %entry, %for.body
38 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
39 %idxprom = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000040 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom
Matt Arsenault0be1cb12013-10-02 22:38:17 +000041 %0 = load i32 addrspace(1)* %arrayidx, align 4
42 %mul = mul nsw i32 %0, 3
Michael Zolotukhin540580c2014-12-02 22:59:02 +000043 %idxprom1 = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000044 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %idxprom1
Matt Arsenault0be1cb12013-10-02 22:38:17 +000045 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
Michael Zolotukhin540580c2014-12-02 22:59:02 +000046 %inc = add nsw i32 %i.02, 1
47 %cmp = icmp slt i32 %inc, %n
48 br i1 %cmp, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +000049
Michael Zolotukhin540580c2014-12-02 22:59:02 +000050for.end: ; preds = %for.body, %entry
Matt Arsenault0be1cb12013-10-02 22:38:17 +000051 ret void
52}
53
54; Parameters are unidentified and different address spaces, so cannot vectorize.
55define 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
60entry:
Michael Zolotukhin540580c2014-12-02 22:59:02 +000061 %cmp1 = icmp slt i32 0, %n
62 br i1 %cmp1, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +000063
Michael Zolotukhin540580c2014-12-02 22:59:02 +000064for.body: ; preds = %entry, %for.body
65 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
66 %idxprom = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000067 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom
Matt Arsenault0be1cb12013-10-02 22:38:17 +000068 %0 = load i32 addrspace(1)* %arrayidx, align 4
69 %mul = mul nsw i32 %0, 3
Michael Zolotukhin540580c2014-12-02 22:59:02 +000070 %idxprom1 = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000071 %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1
Matt Arsenault0be1cb12013-10-02 22:38:17 +000072 store i32 %mul, i32* %arrayidx2, align 4
Michael Zolotukhin540580c2014-12-02 22:59:02 +000073 %inc = add nsw i32 %i.02, 1
74 %cmp = icmp slt i32 %inc, %n
75 br i1 %cmp, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +000076
Michael Zolotukhin540580c2014-12-02 22:59:02 +000077for.end: ; preds = %for.body, %entry
Matt Arsenault0be1cb12013-10-02 22:38:17 +000078 ret void
79}
80
81; Swapped arguments should be the same
82define 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
87entry:
Michael Zolotukhin540580c2014-12-02 22:59:02 +000088 %cmp1 = icmp slt i32 0, %n
89 br i1 %cmp1, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +000090
Michael Zolotukhin540580c2014-12-02 22:59:02 +000091for.body: ; preds = %entry, %for.body
92 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
93 %idxprom = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000094 %arrayidx = getelementptr inbounds i32, i32* %b, i64 %idxprom
Matt Arsenault0be1cb12013-10-02 22:38:17 +000095 %0 = load i32* %arrayidx, align 4
96 %mul = mul nsw i32 %0, 3
Michael Zolotukhin540580c2014-12-02 22:59:02 +000097 %idxprom1 = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000098 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %idxprom1
Matt Arsenault0be1cb12013-10-02 22:38:17 +000099 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000100 %inc = add nsw i32 %i.02, 1
101 %cmp = icmp slt i32 %inc, %n
102 br i1 %cmp, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000103
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000104for.end: ; preds = %for.body, %entry
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000105 ret void
106}
107
108; We should still be able to vectorize with noalias even if the
109; address spaces are different.
110define 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
115entry:
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000116 %cmp1 = icmp slt i32 0, %n
117 br i1 %cmp1, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000118
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000119for.body: ; preds = %entry, %for.body
120 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
121 %idxprom = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000122 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000123 %0 = load i32 addrspace(1)* %arrayidx, align 4
124 %mul = mul nsw i32 %0, 3
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000125 %idxprom1 = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000126 %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000127 store i32 %mul, i32* %arrayidx2, align 4
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000128 %inc = add nsw i32 %i.02, 1
129 %cmp = icmp slt i32 %inc, %n
130 br i1 %cmp, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000131
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000132for.end: ; preds = %for.body, %entry
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000133 ret void
134}
135
136; Store to identified global with different address space. This isn't
137; generally safe and shouldn't be vectorized.
138define void @arst0(i32* %b, i32 %n) #0 {
139; CHECK-LABEL: @arst0(
140; CHECK-NOT: <4 x i32>
141; CHECK: ret
142
143entry:
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000144 %cmp1 = icmp slt i32 0, %n
145 br i1 %cmp1, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000146
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000147for.body: ; preds = %entry, %for.body
148 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
149 %idxprom = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000150 %arrayidx = getelementptr inbounds i32, i32* %b, i64 %idxprom
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000151 %0 = load i32* %arrayidx, align 4
152 %mul = mul nsw i32 %0, 3
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000153 %idxprom1 = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000154 %arrayidx2 = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom1
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000155 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000156 %inc = add nsw i32 %i.02, 1
157 %cmp = icmp slt i32 %inc, %n
158 br i1 %cmp, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000159
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000160for.end: ; preds = %for.body, %entry
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000161 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.
167define void @arst1(i32* %b, i32 %n) #0 {
168; CHECK-LABEL: @arst1(
169; CHECK-NOT: <4 x i32>
170; CHECK: ret
171
172entry:
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000173 %cmp1 = icmp slt i32 0, %n
174 br i1 %cmp1, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000175
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000176for.body: ; preds = %entry, %for.body
177 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
178 %idxprom = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000179 %arrayidx = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000180 %0 = load i32 addrspace(1)* %arrayidx, align 4
181 %mul = mul nsw i32 %0, 3
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000182 %idxprom1 = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000183 %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %idxprom1
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000184 store i32 %mul, i32* %arrayidx2, align 4
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000185 %inc = add nsw i32 %i.02, 1
186 %cmp = icmp slt i32 %inc, %n
187 br i1 %cmp, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000188
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000189for.end: ; preds = %for.body, %entry
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000190 ret void
191}
192
193; Read and write to 2 identified globals in different address
194; spaces. This should be vectorized.
195define void @aoeu(i32 %n) #0 {
196; CHECK-LABEL: @aoeu(
197; CHECK: <4 x i32>
198; CHECK: ret
199
200entry:
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000201 %cmp1 = icmp slt i32 0, %n
202 br i1 %cmp1, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000203
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000204for.body: ; preds = %entry, %for.body
205 %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
206 %idxprom = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000207 %arrayidx = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(2)* @q_as2, i64 0, i64 %idxprom
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000208 %0 = load i32 addrspace(2)* %arrayidx, align 4
209 %mul = mul nsw i32 %0, 3
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000210 %idxprom1 = sext i32 %i.02 to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000211 %arrayidx2 = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom1
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000212 store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000213 %inc = add nsw i32 %i.02, 1
214 %cmp = icmp slt i32 %inc, %n
215 br i1 %cmp, label %for.body, label %for.end
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000216
Michael Zolotukhin540580c2014-12-02 22:59:02 +0000217for.end: ; preds = %for.body, %entry
Matt Arsenault0be1cb12013-10-02 22:38:17 +0000218 ret void
219}
220
221attributes #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" }