@@ -221,18 +221,6 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
221221 return createUnrollAndJamMetadata (Attrs, LoopProperties, HasUserTransforms);
222222 }
223223
224- // Apply all loop properties to the vectorized loop.
225- SmallVector<Metadata *, 4 > FollowupLoopProperties;
226- FollowupLoopProperties.append (LoopProperties.begin (), LoopProperties.end ());
227-
228- // Don't vectorize an already vectorized loop.
229- FollowupLoopProperties.push_back (
230- MDNode::get (Ctx, MDString::get (Ctx, " llvm.loop.isvectorized" )));
231-
232- bool FollowupHasTransforms = false ;
233- SmallVector<Metadata *, 4 > Followup = createUnrollAndJamMetadata (
234- Attrs, FollowupLoopProperties, FollowupHasTransforms);
235-
236224 SmallVector<Metadata *, 4 > Args;
237225 Args.append (LoopProperties.begin (), LoopProperties.end ());
238226
@@ -286,22 +274,46 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
286274 // 5) it is implied when vectorize.width is unset (0) and the user
287275 // explicitly requested fixed-width vectorization, i.e.
288276 // vectorize.scalable.enable is false.
277+ bool VectorizeEnabled = false ;
289278 if (Attrs.VectorizeEnable != LoopAttributes::Unspecified ||
290279 (IsVectorPredicateEnabled && Attrs.VectorizeWidth != 1 ) ||
291280 Attrs.VectorizeWidth > 1 ||
292281 Attrs.VectorizeScalable == LoopAttributes::Enable ||
293282 (Attrs.VectorizeScalable == LoopAttributes::Disable &&
294283 Attrs.VectorizeWidth != 1 )) {
295- bool AttrVal = Attrs.VectorizeEnable != LoopAttributes::Disable;
284+ VectorizeEnabled = Attrs.VectorizeEnable != LoopAttributes::Disable;
296285 Args.push_back (
297286 MDNode::get (Ctx, {MDString::get (Ctx, " llvm.loop.vectorize.enable" ),
298287 ConstantAsMetadata::get (ConstantInt::get (
299- llvm::Type::getInt1Ty (Ctx), AttrVal ))}));
288+ llvm::Type::getInt1Ty (Ctx), VectorizeEnabled ))}));
300289 }
301290
302- if (FollowupHasTransforms)
303- Args.push_back (
304- createFollowupMetadata (" llvm.loop.vectorize.followup_all" , Followup));
291+ // Apply all loop properties to the vectorized loop.
292+ SmallVector<Metadata *, 4 > FollowupLoopProperties;
293+
294+ // If vectorization is not explicitly enabled, the follow-up metadata will be
295+ // directly appended to the list currently being created. In that case, adding
296+ // LoopProperties to FollowupLoopProperties would result in duplication.
297+ if (VectorizeEnabled)
298+ FollowupLoopProperties.append (LoopProperties.begin (), LoopProperties.end ());
299+
300+ // Don't vectorize an already vectorized loop.
301+ FollowupLoopProperties.push_back (
302+ MDNode::get (Ctx, MDString::get (Ctx, " llvm.loop.isvectorized" )));
303+
304+ bool FollowupHasTransforms = false ;
305+ SmallVector<Metadata *, 4 > Followup = createUnrollAndJamMetadata (
306+ Attrs, FollowupLoopProperties, FollowupHasTransforms);
307+
308+ if (FollowupHasTransforms) {
309+ // If vectorization is explicitly enabled, we create a follow-up metadata,
310+ // otherwise directly add the contents of it to Args.
311+ if (VectorizeEnabled)
312+ Args.push_back (
313+ createFollowupMetadata (" llvm.loop.vectorize.followup_all" , Followup));
314+ else
315+ Args.append (Followup.begin (), Followup.end ());
316+ }
305317
306318 HasUserTransforms = true ;
307319 return Args;
0 commit comments