1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-vectorize -S -prefer-predicate-over-epilogue=scalar-epilogue < %s | FileCheck %s
4 target triple = "aarch64-unknown-linux-gnu"
6 ; Test cases for PR60831.
8 define void @test_invar_gep(ptr %dst) #0 {
9 ; CHECK-LABEL: @test_invar_gep(
11 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
12 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
13 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 100, [[TMP1]]
14 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
16 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
17 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
18 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 100, [[TMP3]]
19 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 100, [[N_MOD_VF]]
20 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
21 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 4
22 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
24 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
25 ; CHECK-NEXT: [[TMP6:%.*]] = call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
26 ; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[INDEX]], i64 0
27 ; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[DOTSPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
28 ; CHECK-NEXT: [[TMP7:%.*]] = add <vscale x 4 x i64> zeroinitializer, [[TMP6]]
29 ; CHECK-NEXT: [[TMP8:%.*]] = mul <vscale x 4 x i64> [[TMP7]], shufflevector (<vscale x 4 x i64> insertelement (<vscale x 4 x i64> poison, i64 1, i64 0), <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer)
30 ; CHECK-NEXT: [[TMP9:%.*]] = add <vscale x 4 x i64> [[DOTSPLAT]], [[TMP8]]
31 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX]], 0
32 ; CHECK-NEXT: [[TMP11:%.*]] = add i64 [[INDEX]], 1
33 ; CHECK-NEXT: [[TMP12:%.*]] = add i64 [[INDEX]], 2
34 ; CHECK-NEXT: [[TMP13:%.*]] = add i64 [[INDEX]], 3
35 ; CHECK-NEXT: [[TMP14:%.*]] = getelementptr i8, ptr [[DST:%.*]], i64 0
36 ; CHECK-NEXT: [[TMP15:%.*]] = call i32 @llvm.vscale.i32()
37 ; CHECK-NEXT: [[TMP16:%.*]] = mul i32 [[TMP15]], 4
38 ; CHECK-NEXT: [[TMP17:%.*]] = sub i32 [[TMP16]], 1
39 ; CHECK-NEXT: [[TMP18:%.*]] = extractelement <vscale x 4 x i64> [[TMP9]], i32 [[TMP17]]
40 ; CHECK-NEXT: store i64 [[TMP18]], ptr [[TMP14]], align 1
41 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
42 ; CHECK-NEXT: [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
43 ; CHECK-NEXT: br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
44 ; CHECK: middle.block:
45 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 100, [[N_VEC]]
46 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
48 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
49 ; CHECK-NEXT: br label [[LOOP:%.*]]
51 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
52 ; CHECK-NEXT: [[GEP_INVAR:%.*]] = getelementptr i8, ptr [[DST]], i64 0
53 ; CHECK-NEXT: store i64 [[IV]], ptr [[GEP_INVAR]], align 1
54 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
55 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], 100
56 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP4:![0-9]+]]
58 ; CHECK-NEXT: ret void
64 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
65 %gep.invar = getelementptr i8, ptr %dst, i64 0
66 store i64 %iv, ptr %gep.invar, align 1
67 %iv.next = add nsw i64 %iv, 1
68 %ec = icmp eq i64 %iv.next, 100
69 br i1 %ec, label %exit, label %loop, !llvm.loop !0
75 define void @test_loop2(i64 %n, ptr %dst) {
76 ; CHECK-LABEL: @test_loop2(
77 ; CHECK-NEXT: iter.check:
78 ; CHECK-NEXT: br i1 false, label [[VEC_EPILOG_SCALAR_PH:%.*]], label [[VECTOR_MAIN_LOOP_ITER_CHECK:%.*]]
79 ; CHECK: vector.main.loop.iter.check:
80 ; CHECK-NEXT: br i1 false, label [[VEC_EPILOG_PH:%.*]], label [[VECTOR_PH:%.*]]
82 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
84 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
85 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
86 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 1
87 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 2
88 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 3
89 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], 4
90 ; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[INDEX]], 5
91 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 6
92 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[INDEX]], 7
93 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[INDEX]], 8
94 ; CHECK-NEXT: [[TMP9:%.*]] = add i64 [[INDEX]], 9
95 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX]], 10
96 ; CHECK-NEXT: [[TMP11:%.*]] = add i64 [[INDEX]], 11
97 ; CHECK-NEXT: [[TMP12:%.*]] = add i64 [[INDEX]], 12
98 ; CHECK-NEXT: [[TMP13:%.*]] = add i64 [[INDEX]], 13
99 ; CHECK-NEXT: [[TMP14:%.*]] = add i64 [[INDEX]], 14
100 ; CHECK-NEXT: [[TMP15:%.*]] = add i64 [[INDEX]], 15
101 ; CHECK-NEXT: [[TMP16:%.*]] = sub nsw i64 [[N:%.*]], [[TMP0]]
102 ; CHECK-NEXT: [[TMP17:%.*]] = sub nsw i64 [[N]], [[TMP1]]
103 ; CHECK-NEXT: [[TMP18:%.*]] = sub nsw i64 [[N]], [[TMP2]]
104 ; CHECK-NEXT: [[TMP19:%.*]] = sub nsw i64 [[N]], [[TMP3]]
105 ; CHECK-NEXT: [[TMP20:%.*]] = sub nsw i64 [[N]], [[TMP4]]
106 ; CHECK-NEXT: [[TMP21:%.*]] = sub nsw i64 [[N]], [[TMP5]]
107 ; CHECK-NEXT: [[TMP22:%.*]] = sub nsw i64 [[N]], [[TMP6]]
108 ; CHECK-NEXT: [[TMP23:%.*]] = sub nsw i64 [[N]], [[TMP7]]
109 ; CHECK-NEXT: [[TMP24:%.*]] = sub nsw i64 [[N]], [[TMP8]]
110 ; CHECK-NEXT: [[TMP25:%.*]] = sub nsw i64 [[N]], [[TMP9]]
111 ; CHECK-NEXT: [[TMP26:%.*]] = sub nsw i64 [[N]], [[TMP10]]
112 ; CHECK-NEXT: [[TMP27:%.*]] = sub nsw i64 [[N]], [[TMP11]]
113 ; CHECK-NEXT: [[TMP28:%.*]] = sub nsw i64 [[N]], [[TMP12]]
114 ; CHECK-NEXT: [[TMP29:%.*]] = sub nsw i64 [[N]], [[TMP13]]
115 ; CHECK-NEXT: [[TMP30:%.*]] = sub nsw i64 [[N]], [[TMP14]]
116 ; CHECK-NEXT: [[TMP31:%.*]] = sub nsw i64 [[N]], [[TMP15]]
117 ; CHECK-NEXT: [[TMP32:%.*]] = insertelement <16 x i64> poison, i64 [[TMP16]], i32 0
118 ; CHECK-NEXT: [[TMP33:%.*]] = insertelement <16 x i64> [[TMP32]], i64 [[TMP17]], i32 1
119 ; CHECK-NEXT: [[TMP34:%.*]] = insertelement <16 x i64> [[TMP33]], i64 [[TMP18]], i32 2
120 ; CHECK-NEXT: [[TMP35:%.*]] = insertelement <16 x i64> [[TMP34]], i64 [[TMP19]], i32 3
121 ; CHECK-NEXT: [[TMP36:%.*]] = insertelement <16 x i64> [[TMP35]], i64 [[TMP20]], i32 4
122 ; CHECK-NEXT: [[TMP37:%.*]] = insertelement <16 x i64> [[TMP36]], i64 [[TMP21]], i32 5
123 ; CHECK-NEXT: [[TMP38:%.*]] = insertelement <16 x i64> [[TMP37]], i64 [[TMP22]], i32 6
124 ; CHECK-NEXT: [[TMP39:%.*]] = insertelement <16 x i64> [[TMP38]], i64 [[TMP23]], i32 7
125 ; CHECK-NEXT: [[TMP40:%.*]] = insertelement <16 x i64> [[TMP39]], i64 [[TMP24]], i32 8
126 ; CHECK-NEXT: [[TMP41:%.*]] = insertelement <16 x i64> [[TMP40]], i64 [[TMP25]], i32 9
127 ; CHECK-NEXT: [[TMP42:%.*]] = insertelement <16 x i64> [[TMP41]], i64 [[TMP26]], i32 10
128 ; CHECK-NEXT: [[TMP43:%.*]] = insertelement <16 x i64> [[TMP42]], i64 [[TMP27]], i32 11
129 ; CHECK-NEXT: [[TMP44:%.*]] = insertelement <16 x i64> [[TMP43]], i64 [[TMP28]], i32 12
130 ; CHECK-NEXT: [[TMP45:%.*]] = insertelement <16 x i64> [[TMP44]], i64 [[TMP29]], i32 13
131 ; CHECK-NEXT: [[TMP46:%.*]] = insertelement <16 x i64> [[TMP45]], i64 [[TMP30]], i32 14
132 ; CHECK-NEXT: [[TMP47:%.*]] = insertelement <16 x i64> [[TMP46]], i64 [[TMP31]], i32 15
133 ; CHECK-NEXT: [[TMP48:%.*]] = trunc <16 x i64> [[TMP47]] to <16 x i8>
134 ; CHECK-NEXT: [[TMP49:%.*]] = add i64 [[TMP0]], [[TMP16]]
135 ; CHECK-NEXT: [[TMP50:%.*]] = getelementptr i8, ptr [[DST:%.*]], i64 [[TMP49]]
136 ; CHECK-NEXT: [[TMP51:%.*]] = extractelement <16 x i8> [[TMP48]], i32 15
137 ; CHECK-NEXT: store i8 [[TMP51]], ptr [[TMP50]], align 1
138 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
139 ; CHECK-NEXT: [[TMP52:%.*]] = icmp eq i64 [[INDEX_NEXT]], 992
140 ; CHECK-NEXT: br i1 [[TMP52]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
141 ; CHECK: middle.block:
142 ; CHECK-NEXT: br i1 false, label [[EXIT:%.*]], label [[VEC_EPILOG_ITER_CHECK:%.*]]
143 ; CHECK: vec.epilog.iter.check:
144 ; CHECK-NEXT: br i1 false, label [[VEC_EPILOG_SCALAR_PH]], label [[VEC_EPILOG_PH]]
145 ; CHECK: vec.epilog.ph:
146 ; CHECK-NEXT: [[VEC_EPILOG_RESUME_VAL:%.*]] = phi i64 [ 992, [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
147 ; CHECK-NEXT: br label [[VEC_EPILOG_VECTOR_BODY:%.*]]
148 ; CHECK: vec.epilog.vector.body:
149 ; CHECK-NEXT: [[INDEX2:%.*]] = phi i64 [ [[VEC_EPILOG_RESUME_VAL]], [[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT3:%.*]], [[VEC_EPILOG_VECTOR_BODY]] ]
150 ; CHECK-NEXT: [[TMP53:%.*]] = add i64 [[INDEX2]], 0
151 ; CHECK-NEXT: [[TMP54:%.*]] = add i64 [[INDEX2]], 1
152 ; CHECK-NEXT: [[TMP55:%.*]] = add i64 [[INDEX2]], 2
153 ; CHECK-NEXT: [[TMP56:%.*]] = add i64 [[INDEX2]], 3
154 ; CHECK-NEXT: [[TMP57:%.*]] = add i64 [[INDEX2]], 4
155 ; CHECK-NEXT: [[TMP58:%.*]] = add i64 [[INDEX2]], 5
156 ; CHECK-NEXT: [[TMP59:%.*]] = add i64 [[INDEX2]], 6
157 ; CHECK-NEXT: [[TMP60:%.*]] = add i64 [[INDEX2]], 7
158 ; CHECK-NEXT: [[TMP61:%.*]] = sub nsw i64 [[N]], [[TMP53]]
159 ; CHECK-NEXT: [[TMP62:%.*]] = sub nsw i64 [[N]], [[TMP54]]
160 ; CHECK-NEXT: [[TMP63:%.*]] = sub nsw i64 [[N]], [[TMP55]]
161 ; CHECK-NEXT: [[TMP64:%.*]] = sub nsw i64 [[N]], [[TMP56]]
162 ; CHECK-NEXT: [[TMP65:%.*]] = sub nsw i64 [[N]], [[TMP57]]
163 ; CHECK-NEXT: [[TMP66:%.*]] = sub nsw i64 [[N]], [[TMP58]]
164 ; CHECK-NEXT: [[TMP67:%.*]] = sub nsw i64 [[N]], [[TMP59]]
165 ; CHECK-NEXT: [[TMP68:%.*]] = sub nsw i64 [[N]], [[TMP60]]
166 ; CHECK-NEXT: [[TMP69:%.*]] = insertelement <8 x i64> poison, i64 [[TMP61]], i32 0
167 ; CHECK-NEXT: [[TMP70:%.*]] = insertelement <8 x i64> [[TMP69]], i64 [[TMP62]], i32 1
168 ; CHECK-NEXT: [[TMP71:%.*]] = insertelement <8 x i64> [[TMP70]], i64 [[TMP63]], i32 2
169 ; CHECK-NEXT: [[TMP72:%.*]] = insertelement <8 x i64> [[TMP71]], i64 [[TMP64]], i32 3
170 ; CHECK-NEXT: [[TMP73:%.*]] = insertelement <8 x i64> [[TMP72]], i64 [[TMP65]], i32 4
171 ; CHECK-NEXT: [[TMP74:%.*]] = insertelement <8 x i64> [[TMP73]], i64 [[TMP66]], i32 5
172 ; CHECK-NEXT: [[TMP75:%.*]] = insertelement <8 x i64> [[TMP74]], i64 [[TMP67]], i32 6
173 ; CHECK-NEXT: [[TMP76:%.*]] = insertelement <8 x i64> [[TMP75]], i64 [[TMP68]], i32 7
174 ; CHECK-NEXT: [[TMP77:%.*]] = trunc <8 x i64> [[TMP76]] to <8 x i8>
175 ; CHECK-NEXT: [[TMP78:%.*]] = add i64 [[TMP53]], [[TMP61]]
176 ; CHECK-NEXT: [[TMP79:%.*]] = getelementptr i8, ptr [[DST]], i64 [[TMP78]]
177 ; CHECK-NEXT: [[TMP80:%.*]] = extractelement <8 x i8> [[TMP77]], i32 7
178 ; CHECK-NEXT: store i8 [[TMP80]], ptr [[TMP79]], align 1
179 ; CHECK-NEXT: [[INDEX_NEXT3]] = add nuw i64 [[INDEX2]], 8
180 ; CHECK-NEXT: [[TMP81:%.*]] = icmp eq i64 [[INDEX_NEXT3]], 1000
181 ; CHECK-NEXT: br i1 [[TMP81]], label [[VEC_EPILOG_MIDDLE_BLOCK:%.*]], label [[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
182 ; CHECK: vec.epilog.middle.block:
183 ; CHECK-NEXT: br i1 false, label [[EXIT]], label [[VEC_EPILOG_SCALAR_PH]]
184 ; CHECK: vec.epilog.scalar.ph:
185 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1000, [[VEC_EPILOG_MIDDLE_BLOCK]] ], [ 992, [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[ITER_CHECK:%.*]] ]
186 ; CHECK-NEXT: br label [[LOOP:%.*]]
188 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[VEC_EPILOG_SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
189 ; CHECK-NEXT: [[SUB_N:%.*]] = sub nsw i64 [[N]], [[IV]]
190 ; CHECK-NEXT: [[SUB_N_TRUNC:%.*]] = trunc i64 [[SUB_N]] to i8
191 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[IV]], [[SUB_N]]
192 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[DST]], i64 [[ADD]]
193 ; CHECK-NEXT: store i8 [[SUB_N_TRUNC]], ptr [[GEP]], align 1
194 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
195 ; CHECK-NEXT: [[C:%.*]] = icmp sle i64 [[IV_NEXT]], 1000
196 ; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[EXIT]], !llvm.loop [[LOOP7:![0-9]+]]
198 ; CHECK-NEXT: ret void
204 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
205 %sub.n = sub nsw i64 %n, %iv
206 %sub.n.trunc = trunc i64 %sub.n to i8
207 %add = add i64 %iv, %sub.n
208 %gep = getelementptr i8, ptr %dst, i64 %add
209 store i8 %sub.n.trunc, ptr %gep, align 1
210 %iv.next = add nsw i64 %iv, 1
211 %c = icmp sle i64 %iv.next, 1000
212 br i1 %c, label %loop, label %exit
218 attributes #0 = { "target-features"="+neon,+sve" vscale_range(1, 16) }
220 !0 = distinct !{!0, !1, !2, !3, !4, !5}
221 !1 = !{!"llvm.loop.mustprogress"}
222 !2 = !{!"llvm.loop.vectorize.width", i32 4}
223 !3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
224 !4 = !{!"llvm.loop.vectorize.enable", i1 true}
225 !5 = !{!"llvm.loop.interleave.count", i32 1}