3 ; RUN: opt -loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -prefer-inloop-reductions -enable-interleaved-mem-accesses=true -enable-masked-interleaved-mem-accesses -disable-output %s 2>&1 | FileCheck %s
5 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
7 ; Tests for printing VPlans.
9 define void @print_call_and_memory(i64 %n, float* noalias %y, float* noalias %x) nounwind uwtable {
10 ; CHECK-LABEL: Checking a loop in "print_call_and_memory"
11 ; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
12 ; CHECK-NEXT: for.body:
13 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi %iv.next, 0
14 ; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr ir<%y>, ir<%iv>
15 ; CHECK-NEXT: WIDEN ir<%lv> = load ir<%arrayidx>
16 ; CHECK-NEXT: WIDEN-CALL ir<%call> = call @llvm.sqrt.f32(ir<%lv>)
17 ; CHECK-NEXT: CLONE ir<%arrayidx2> = getelementptr ir<%x>, ir<%iv>
18 ; CHECK-NEXT: WIDEN store ir<%arrayidx2>, ir<%call>
19 ; CHECK-NEXT: No successors
23 %cmp6 = icmp sgt i64 %n, 0
24 br i1 %cmp6, label %for.body, label %for.end
26 for.body: ; preds = %entry, %for.body
27 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
28 %arrayidx = getelementptr inbounds float, float* %y, i64 %iv
29 %lv = load float, float* %arrayidx, align 4
30 %call = tail call float @llvm.sqrt.f32(float %lv) nounwind readnone
31 %arrayidx2 = getelementptr inbounds float, float* %x, i64 %iv
32 store float %call, float* %arrayidx2, align 4
33 %iv.next = add i64 %iv, 1
34 %exitcond = icmp eq i64 %iv.next, %n
35 br i1 %exitcond, label %for.end, label %for.body
37 for.end: ; preds = %for.body, %entry
41 define void @print_widen_gep_and_select(i64 %n, float* noalias %y, float* noalias %x, float* %z) nounwind uwtable {
42 ; CHECK-LABEL: Checking a loop in "print_widen_gep_and_select"
43 ; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
44 ; CHECK-NEXT: for.body:
45 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi %iv.next, 0
46 ; CHECK-NEXT: WIDEN-GEP Inv[Var] ir<%arrayidx> = getelementptr ir<%y>, ir<%iv>
47 ; CHECK-NEXT: WIDEN ir<%lv> = load ir<%arrayidx>
48 ; CHECK-NEXT: WIDEN ir<%cmp> = icmp ir<%arrayidx>, ir<%z>
49 ; CHECK-NEXT: WIDEN-SELECT ir<%sel> = select ir<%cmp>, ir<1.000000e+01>, ir<2.000000e+01>
50 ; CHECK-NEXT: WIDEN ir<%add> = fadd ir<%lv>, ir<%sel>
51 ; CHECK-NEXT: CLONE ir<%arrayidx2> = getelementptr ir<%x>, ir<%iv>
52 ; CHECK-NEXT: WIDEN store ir<%arrayidx2>, ir<%add>
53 ; CHECK-NEXT: No successors
57 %cmp6 = icmp sgt i64 %n, 0
58 br i1 %cmp6, label %for.body, label %for.end
60 for.body: ; preds = %entry, %for.body
61 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
62 %arrayidx = getelementptr inbounds float, float* %y, i64 %iv
63 %lv = load float, float* %arrayidx, align 4
64 %cmp = icmp eq float* %arrayidx, %z
65 %sel = select i1 %cmp, float 10.0, float 20.0
66 %add = fadd float %lv, %sel
67 %arrayidx2 = getelementptr inbounds float, float* %x, i64 %iv
68 store float %add, float* %arrayidx2, align 4
69 %iv.next = add i64 %iv, 1
70 %exitcond = icmp eq i64 %iv.next, %n
71 br i1 %exitcond, label %for.end, label %for.body
73 for.end: ; preds = %for.body, %entry
77 define float @print_reduction(i64 %n, float* noalias %y) {
78 ; CHECK-LABEL: Checking a loop in "print_reduction"
79 ; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
80 ; CHECK-NEXT: for.body:
81 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi %iv.next, 0
82 ; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%red> = phi ir<0.000000e+00>, ir<%red.next>
83 ; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr ir<%y>, ir<%iv>
84 ; CHECK-NEXT: WIDEN ir<%lv> = load ir<%arrayidx>
85 ; CHECK-NEXT: REDUCE ir<%red.next> = ir<%red> + reduce.fadd (ir<%lv>)
86 ; CHECK-NEXT: No successors
92 for.body: ; preds = %entry, %for.body
93 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
94 %red = phi float [ %red.next, %for.body ], [ 0.0, %entry ]
95 %arrayidx = getelementptr inbounds float, float* %y, i64 %iv
96 %lv = load float, float* %arrayidx, align 4
97 %red.next = fadd fast float %lv, %red
98 %iv.next = add i64 %iv, 1
99 %exitcond = icmp eq i64 %iv.next, %n
100 br i1 %exitcond, label %for.end, label %for.body
102 for.end: ; preds = %for.body, %entry
106 define void @print_replicate_predicated_phi(i64 %n, i64* %x) {
107 ; CHECK-LABEL: Checking a loop in "print_replicate_predicated_phi"
108 ; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
109 ; CHECK-NEXT: for.body:
110 ; CHECK-NEXT: WIDEN-INDUCTION %i = phi 0, %i.next
111 ; CHECK-NEXT: WIDEN ir<%cmp> = icmp ir<%i>, ir<5>
112 ; CHECK-NEXT: Successor(s): if.then
114 ; CHECK-NEXT: if.then:
115 ; CHECK-NEXT: Successor(s): pred.udiv
117 ; CHECK-NEXT: <xVFxUF> pred.udiv: {
118 ; CHECK-NEXT: pred.udiv.entry:
119 ; CHECK-NEXT: BRANCH-ON-MASK ir<%cmp>
120 ; CHECK-NEXT: Successor(s): pred.udiv.if, pred.udiv.continue
121 ; CHECK-NEXT: CondBit: ir<%cmp>
123 ; CHECK-NEXT: pred.udiv.if:
124 ; CHECK-NEXT: REPLICATE ir<%tmp4> = udiv ir<%n>, ir<%i> (S->V)
125 ; CHECK-NEXT: Successor(s): pred.udiv.continue
127 ; CHECK-NEXT: pred.udiv.continue:
128 ; CHECK-NEXT: PHI-PREDICATED-INSTRUCTION vp<%3> = ir<%tmp4>
129 ; CHECK-NEXT: No successors
131 ; CHECK-NEXT: Successor(s): if.then.0
133 ; CHECK-NEXT: if.then.0:
134 ; CHECK-NEXT: Successor(s): for.inc
136 ; CHECK-NEXT: for.inc:
137 ; CHECK-NEXT: EMIT vp<%4> = not ir<%cmp>
138 ; CHECK-NEXT: BLEND %d = ir<0>/vp<%4> vp<%3>/ir<%cmp>
139 ; CHECK-NEXT: CLONE ir<%idx> = getelementptr ir<%x>, ir<%i>
140 ; CHECK-NEXT: WIDEN store ir<%idx>, ir<%d>
141 ; CHECK-NEXT: No successors
147 for.body: ; preds = %for.inc, %entry
148 %i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ]
149 %cmp = icmp ult i64 %i, 5
150 br i1 %cmp, label %if.then, label %for.inc
152 if.then: ; preds = %for.body
153 %tmp4 = udiv i64 %n, %i
156 for.inc: ; preds = %if.then, %for.body
157 %d = phi i64 [ 0, %for.body ], [ %tmp4, %if.then ]
158 %idx = getelementptr i64, i64* %x, i64 %i
159 store i64 %d, i64* %idx
160 %i.next = add nuw nsw i64 %i, 1
161 %cond = icmp slt i64 %i.next, %n
162 br i1 %cond, label %for.body, label %for.end
164 for.end: ; preds = %for.inc
168 @AB = common global [1024 x i32] zeroinitializer, align 4
169 @CD = common global [1024 x i32] zeroinitializer, align 4
171 define void @print_interleave_groups(i32 %C, i32 %D) {
172 ; CHECK-LABEL: Checking a loop in "print_interleave_groups"
173 ; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
174 ; CHECK-NEXT: for.body:
175 ; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next
176 ; CHECK-NEXT: CLONE ir<%gep.AB.0> = getelementptr ir<@AB>, ir<0>, ir<%iv>
177 ; CHECK-NEXT: INTERLEAVE-GROUP with factor 4 at %AB.0, ir<%gep.AB.0>
178 ; CHECK-NEXT: ir<%AB.0> = load from index 0
179 ; CHECK-NEXT: ir<%AB.1> = load from index 1
180 ; CHECK-NEXT: ir<%AB.3> = load from index 3
181 ; CHECK-NEXT: CLONE ir<%iv.plus.1> = add ir<%iv>, ir<1>
182 ; CHECK-NEXT: CLONE ir<%gep.AB.1> = getelementptr ir<@AB>, ir<0>, ir<%iv.plus.1>
183 ; CHECK-NEXT: CLONE ir<%iv.plus.2> = add ir<%iv>, ir<2>
184 ; CHECK-NEXT: CLONE ir<%iv.plus.3> = add ir<%iv>, ir<3>
185 ; CHECK-NEXT: CLONE ir<%gep.AB.3> = getelementptr ir<@AB>, ir<0>, ir<%iv.plus.3>
186 ; CHECK-NEXT: WIDEN ir<%add> = add ir<%AB.0>, ir<%AB.1>
187 ; CHECK-NEXT: CLONE ir<%gep.CD.0> = getelementptr ir<@CD>, ir<0>, ir<%iv>
188 ; CHECK-NEXT: CLONE ir<%gep.CD.1> = getelementptr ir<@CD>, ir<0>, ir<%iv.plus.1>
189 ; CHECK-NEXT: CLONE ir<%gep.CD.2> = getelementptr ir<@CD>, ir<0>, ir<%iv.plus.2>
190 ; CHECK-NEXT: CLONE ir<%gep.CD.3> = getelementptr ir<@CD>, ir<0>, ir<%iv.plus.3>
191 ; CHECK-NEXT: INTERLEAVE-GROUP with factor 4 at <badref>, ir<%gep.CD.3>
192 ; CHECK-NEXT: store ir<%add> to index 0
193 ; CHECK-NEXT: store ir<1> to index 1
194 ; CHECK-NEXT: store ir<2> to index 2
195 ; CHECK-NEXT: store ir<%AB.3> to index 3
196 ; CHECK-NEXT: No successors
203 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
204 %gep.AB.0= getelementptr inbounds [1024 x i32], [1024 x i32]* @AB, i64 0, i64 %iv
205 %AB.0 = load i32, i32* %gep.AB.0, align 4
206 %iv.plus.1 = add i64 %iv, 1
207 %gep.AB.1 = getelementptr inbounds [1024 x i32], [1024 x i32]* @AB, i64 0, i64 %iv.plus.1
208 %AB.1 = load i32, i32* %gep.AB.1, align 4
209 %iv.plus.2 = add i64 %iv, 2
210 %iv.plus.3 = add i64 %iv, 3
211 %gep.AB.3 = getelementptr inbounds [1024 x i32], [1024 x i32]* @AB, i64 0, i64 %iv.plus.3
212 %AB.3 = load i32, i32* %gep.AB.3, align 4
213 %add = add nsw i32 %AB.0, %AB.1
214 %gep.CD.0 = getelementptr inbounds [1024 x i32], [1024 x i32]* @CD, i64 0, i64 %iv
215 store i32 %add, i32* %gep.CD.0, align 4
216 %gep.CD.1 = getelementptr inbounds [1024 x i32], [1024 x i32]* @CD, i64 0, i64 %iv.plus.1
217 store i32 1, i32* %gep.CD.1, align 4
218 %gep.CD.2 = getelementptr inbounds [1024 x i32], [1024 x i32]* @CD, i64 0, i64 %iv.plus.2
219 store i32 2, i32* %gep.CD.2, align 4
220 %gep.CD.3 = getelementptr inbounds [1024 x i32], [1024 x i32]* @CD, i64 0, i64 %iv.plus.3
221 store i32 %AB.3, i32* %gep.CD.3, align 4
222 %iv.next = add nuw nsw i64 %iv, 4
223 %cmp = icmp slt i64 %iv.next, 1024
224 br i1 %cmp, label %for.body, label %for.end
230 declare float @llvm.sqrt.f32(float) nounwind readnone