1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; This is the loop in c++ being vectorize in this file with
3 ;experimental.vector.reverse
4 ; #pragma clang loop vectorize_width(8, scalable) interleave_count(2)
5 ; for (int i = N-1; i >= 0; --i)
8 ; RUN: opt -passes=loop-vectorize,dce,instcombine -mtriple aarch64-linux-gnu -S \
9 ; RUN: -prefer-predicate-over-epilogue=scalar-epilogue < %s | FileCheck %s
11 define void @vector_reverse_f64(i64 %N, ptr noalias %a, ptr noalias %b) #0{
12 ; CHECK-LABEL: @vector_reverse_f64(
14 ; CHECK-NEXT: [[CMP7:%.*]] = icmp sgt i64 [[N:%.*]], 0
15 ; CHECK-NEXT: br i1 [[CMP7]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
16 ; CHECK: for.body.preheader:
17 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
18 ; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[TMP0]], 4
19 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ugt i64 [[TMP1]], [[N]]
20 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
22 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
23 ; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP2]], 4
24 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N]], [[TMP3]]
25 ; CHECK-NEXT: [[N_VEC:%.*]] = sub nsw i64 [[N]], [[N_MOD_VF]]
26 ; CHECK-NEXT: [[TMP30:%.*]] = call i64 @llvm.vscale.i64()
27 ; CHECK-NEXT: [[TMP31:%.*]] = shl i64 [[TMP30]], 4
28 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
30 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
31 ; CHECK-NEXT: [[TMP4:%.*]] = xor i64 [[INDEX]], -1
32 ; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[TMP4]], [[N]]
33 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds double, ptr [[B:%.*]], i64 [[TMP5]]
34 ; CHECK-NEXT: [[TMP7:%.*]] = call i64 @llvm.vscale.i64()
35 ; CHECK-NEXT: [[TMP8:%.*]] = shl i64 [[TMP7]], 3
36 ; CHECK-NEXT: [[TMP9:%.*]] = sub i64 1, [[TMP8]]
37 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds double, ptr [[TMP6]], i64 [[TMP9]]
38 ; CHECK-NEXT: [[TMP11:%.*]] = call i64 @llvm.vscale.i64()
39 ; CHECK-NEXT: [[TMP12:%.*]] = shl i64 [[TMP11]], 3
40 ; CHECK-NEXT: [[TMP13:%.*]] = sub i64 0, [[TMP12]]
41 ; CHECK-NEXT: [[TMP14:%.*]] = sub i64 1, [[TMP12]]
42 ; CHECK-NEXT: [[TMP15:%.*]] = getelementptr inbounds double, ptr [[TMP6]], i64 [[TMP13]]
43 ; CHECK-NEXT: [[TMP16:%.*]] = getelementptr inbounds double, ptr [[TMP15]], i64 [[TMP14]]
44 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 8 x double>, ptr [[TMP10]], align 8
45 ; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <vscale x 8 x double>, ptr [[TMP16]], align 8
46 ; CHECK-NEXT: [[TMP17:%.*]] = fadd <vscale x 8 x double> [[WIDE_LOAD]], shufflevector (<vscale x 8 x double> insertelement (<vscale x 8 x double> poison, double 1.000000e+00, i64 0), <vscale x 8 x double> poison, <vscale x 8 x i32> zeroinitializer)
47 ; CHECK-NEXT: [[TMP18:%.*]] = fadd <vscale x 8 x double> [[WIDE_LOAD1]], shufflevector (<vscale x 8 x double> insertelement (<vscale x 8 x double> poison, double 1.000000e+00, i64 0), <vscale x 8 x double> poison, <vscale x 8 x i32> zeroinitializer)
48 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr inbounds double, ptr [[A:%.*]], i64 [[TMP5]]
49 ; CHECK-NEXT: [[TMP20:%.*]] = call i64 @llvm.vscale.i64()
50 ; CHECK-NEXT: [[TMP21:%.*]] = shl i64 [[TMP20]], 3
51 ; CHECK-NEXT: [[TMP22:%.*]] = sub i64 1, [[TMP21]]
52 ; CHECK-NEXT: [[TMP23:%.*]] = getelementptr inbounds double, ptr [[TMP19]], i64 [[TMP22]]
53 ; CHECK-NEXT: [[TMP24:%.*]] = call i64 @llvm.vscale.i64()
54 ; CHECK-NEXT: [[TMP25:%.*]] = shl i64 [[TMP24]], 3
55 ; CHECK-NEXT: [[TMP26:%.*]] = sub i64 0, [[TMP25]]
56 ; CHECK-NEXT: [[TMP27:%.*]] = sub i64 1, [[TMP25]]
57 ; CHECK-NEXT: [[TMP28:%.*]] = getelementptr inbounds double, ptr [[TMP19]], i64 [[TMP26]]
58 ; CHECK-NEXT: [[TMP29:%.*]] = getelementptr inbounds double, ptr [[TMP28]], i64 [[TMP27]]
59 ; CHECK-NEXT: store <vscale x 8 x double> [[TMP17]], ptr [[TMP23]], align 8
60 ; CHECK-NEXT: store <vscale x 8 x double> [[TMP18]], ptr [[TMP29]], align 8
61 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP31]]
62 ; CHECK-NEXT: [[TMP32:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
63 ; CHECK-NEXT: br i1 [[TMP32]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
64 ; CHECK: middle.block:
65 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
66 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]
68 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_MOD_VF]], [[MIDDLE_BLOCK]] ], [ [[N]], [[FOR_BODY_PREHEADER]] ]
69 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
70 ; CHECK: for.cond.cleanup.loopexit:
71 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
72 ; CHECK: for.cond.cleanup:
73 ; CHECK-NEXT: ret void
75 ; CHECK-NEXT: [[I_08_IN:%.*]] = phi i64 [ [[I_08:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
76 ; CHECK-NEXT: [[I_08]] = add nsw i64 [[I_08_IN]], -1
77 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[B]], i64 [[I_08]]
78 ; CHECK-NEXT: [[TMP33:%.*]] = load double, ptr [[ARRAYIDX]], align 8
79 ; CHECK-NEXT: [[ADD:%.*]] = fadd double [[TMP33]], 1.000000e+00
80 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds double, ptr [[A]], i64 [[I_08]]
81 ; CHECK-NEXT: store double [[ADD]], ptr [[ARRAYIDX1]], align 8
82 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[I_08_IN]], 1
83 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP_LOOPEXIT]], !llvm.loop [[LOOP4:![0-9]+]]
86 %cmp7 = icmp sgt i64 %N, 0
87 br i1 %cmp7, label %for.body, label %for.cond.cleanup
89 for.cond.cleanup: ; preds = %for.body
92 for.body: ; preds = %entry, %for.body
93 %i.08.in = phi i64 [ %i.08, %for.body ], [ %N, %entry ]
94 %i.08 = add nsw i64 %i.08.in, -1
95 %arrayidx = getelementptr inbounds double, ptr %b, i64 %i.08
96 %0 = load double, ptr %arrayidx, align 8
97 %add = fadd double %0, 1.000000e+00
98 %arrayidx1 = getelementptr inbounds double, ptr %a, i64 %i.08
99 store double %add, ptr %arrayidx1, align 8
100 %cmp = icmp sgt i64 %i.08.in, 1
101 br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !0
105 define void @vector_reverse_i64(i64 %N, ptr %a, ptr %b) #0 {
106 ; CHECK-LABEL: @vector_reverse_i64(
108 ; CHECK-NEXT: [[A2:%.*]] = ptrtoint ptr [[A:%.*]] to i64
109 ; CHECK-NEXT: [[B1:%.*]] = ptrtoint ptr [[B:%.*]] to i64
110 ; CHECK-NEXT: [[CMP8:%.*]] = icmp sgt i64 [[N:%.*]], 0
111 ; CHECK-NEXT: br i1 [[CMP8]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
112 ; CHECK: for.body.preheader:
113 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
114 ; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[TMP0]], 4
115 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ugt i64 [[TMP1]], [[N]]
116 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
117 ; CHECK: vector.memcheck:
118 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
119 ; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP2]], 7
120 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[B1]], [[A2]]
121 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP4]], [[TMP3]]
122 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
124 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
125 ; CHECK-NEXT: [[TMP6:%.*]] = shl i64 [[TMP5]], 4
126 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N]], [[TMP6]]
127 ; CHECK-NEXT: [[N_VEC:%.*]] = sub nsw i64 [[N]], [[N_MOD_VF]]
128 ; CHECK-NEXT: [[TMP33:%.*]] = call i64 @llvm.vscale.i64()
129 ; CHECK-NEXT: [[TMP34:%.*]] = shl i64 [[TMP33]], 4
130 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
131 ; CHECK: vector.body:
132 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
133 ; CHECK-NEXT: [[TMP7:%.*]] = xor i64 [[INDEX]], -1
134 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[TMP7]], [[N]]
135 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds i64, ptr [[B]], i64 [[TMP8]]
136 ; CHECK-NEXT: [[TMP10:%.*]] = call i64 @llvm.vscale.i64()
137 ; CHECK-NEXT: [[TMP11:%.*]] = shl i64 [[TMP10]], 3
138 ; CHECK-NEXT: [[TMP12:%.*]] = sub i64 1, [[TMP11]]
139 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i64, ptr [[TMP9]], i64 [[TMP12]]
140 ; CHECK-NEXT: [[TMP14:%.*]] = call i64 @llvm.vscale.i64()
141 ; CHECK-NEXT: [[TMP15:%.*]] = shl i64 [[TMP14]], 3
142 ; CHECK-NEXT: [[TMP16:%.*]] = sub i64 0, [[TMP15]]
143 ; CHECK-NEXT: [[TMP17:%.*]] = sub i64 1, [[TMP15]]
144 ; CHECK-NEXT: [[TMP18:%.*]] = getelementptr inbounds i64, ptr [[TMP9]], i64 [[TMP16]]
145 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr inbounds i64, ptr [[TMP18]], i64 [[TMP17]]
146 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 8 x i64>, ptr [[TMP13]], align 8
147 ; CHECK-NEXT: [[WIDE_LOAD3:%.*]] = load <vscale x 8 x i64>, ptr [[TMP19]], align 8
148 ; CHECK-NEXT: [[TMP20:%.*]] = add <vscale x 8 x i64> [[WIDE_LOAD]], shufflevector (<vscale x 8 x i64> insertelement (<vscale x 8 x i64> poison, i64 1, i64 0), <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer)
149 ; CHECK-NEXT: [[TMP21:%.*]] = add <vscale x 8 x i64> [[WIDE_LOAD3]], shufflevector (<vscale x 8 x i64> insertelement (<vscale x 8 x i64> poison, i64 1, i64 0), <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer)
150 ; CHECK-NEXT: [[TMP22:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP8]]
151 ; CHECK-NEXT: [[TMP23:%.*]] = call i64 @llvm.vscale.i64()
152 ; CHECK-NEXT: [[TMP24:%.*]] = shl i64 [[TMP23]], 3
153 ; CHECK-NEXT: [[TMP25:%.*]] = sub i64 1, [[TMP24]]
154 ; CHECK-NEXT: [[TMP26:%.*]] = getelementptr inbounds i64, ptr [[TMP22]], i64 [[TMP25]]
155 ; CHECK-NEXT: [[TMP27:%.*]] = call i64 @llvm.vscale.i64()
156 ; CHECK-NEXT: [[TMP28:%.*]] = shl i64 [[TMP27]], 3
157 ; CHECK-NEXT: [[TMP29:%.*]] = sub i64 0, [[TMP28]]
158 ; CHECK-NEXT: [[TMP30:%.*]] = sub i64 1, [[TMP28]]
159 ; CHECK-NEXT: [[TMP31:%.*]] = getelementptr inbounds i64, ptr [[TMP22]], i64 [[TMP29]]
160 ; CHECK-NEXT: [[TMP32:%.*]] = getelementptr inbounds i64, ptr [[TMP31]], i64 [[TMP30]]
161 ; CHECK-NEXT: store <vscale x 8 x i64> [[TMP20]], ptr [[TMP26]], align 8
162 ; CHECK-NEXT: store <vscale x 8 x i64> [[TMP21]], ptr [[TMP32]], align 8
163 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP34]]
164 ; CHECK-NEXT: [[TMP35:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
165 ; CHECK-NEXT: br i1 [[TMP35]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
166 ; CHECK: middle.block:
167 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
168 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]
170 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_MOD_VF]], [[MIDDLE_BLOCK]] ], [ [[N]], [[FOR_BODY_PREHEADER]] ], [ [[N]], [[VECTOR_MEMCHECK]] ]
171 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
172 ; CHECK: for.cond.cleanup.loopexit:
173 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
174 ; CHECK: for.cond.cleanup:
175 ; CHECK-NEXT: ret void
177 ; CHECK-NEXT: [[I_09_IN:%.*]] = phi i64 [ [[I_09:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
178 ; CHECK-NEXT: [[I_09]] = add nsw i64 [[I_09_IN]], -1
179 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[B]], i64 [[I_09]]
180 ; CHECK-NEXT: [[TMP36:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
181 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[TMP36]], 1
182 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[I_09]]
183 ; CHECK-NEXT: store i64 [[ADD]], ptr [[ARRAYIDX2]], align 8
184 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[I_09_IN]], 1
185 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP_LOOPEXIT]], !llvm.loop [[LOOP6:![0-9]+]]
188 %cmp8 = icmp sgt i64 %N, 0
189 br i1 %cmp8, label %for.body, label %for.cond.cleanup
191 for.cond.cleanup: ; preds = %for.body
194 for.body: ; preds = %entry, %for.body
195 %i.09.in = phi i64 [ %i.09, %for.body ], [ %N, %entry ]
196 %i.09 = add nsw i64 %i.09.in, -1
197 %arrayidx = getelementptr inbounds i64, ptr %b, i64 %i.09
198 %0 = load i64, ptr %arrayidx, align 8
200 %arrayidx2 = getelementptr inbounds i64, ptr %a, i64 %i.09
201 store i64 %add, ptr %arrayidx2, align 8
202 %cmp = icmp sgt i64 %i.09.in, 1
203 br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !0
206 attributes #0 = { "target-cpu"="generic" "target-features"="+neon,+sve" }
208 !0 = distinct !{!0, !1, !2, !3, !4, !5}
209 !1 = !{!"llvm.loop.mustprogress"}
210 !2 = !{!"llvm.loop.vectorize.width", i32 8}
211 !3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
212 !4 = !{!"llvm.loop.vectorize.enable", i1 true}
213 !5 = !{!"llvm.loop.interleave.count", i32 2}