diff options
Diffstat (limited to 'clang/lib/CodeGen/CGLoopInfo.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGLoopInfo.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp index 4a9092842858..b2b569a43038 100644 --- a/clang/lib/CodeGen/CGLoopInfo.cpp +++ b/clang/lib/CodeGen/CGLoopInfo.cpp @@ -221,18 +221,6 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs, return createUnrollAndJamMetadata(Attrs, LoopProperties, HasUserTransforms); } - // Apply all loop properties to the vectorized loop. - SmallVector<Metadata *, 4> FollowupLoopProperties; - FollowupLoopProperties.append(LoopProperties.begin(), LoopProperties.end()); - - // Don't vectorize an already vectorized loop. - FollowupLoopProperties.push_back( - MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.isvectorized"))); - - bool FollowupHasTransforms = false; - SmallVector<Metadata *, 4> Followup = createUnrollAndJamMetadata( - Attrs, FollowupLoopProperties, FollowupHasTransforms); - SmallVector<Metadata *, 4> Args; Args.append(LoopProperties.begin(), LoopProperties.end()); @@ -286,22 +274,46 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs, // 5) it is implied when vectorize.width is unset (0) and the user // explicitly requested fixed-width vectorization, i.e. // vectorize.scalable.enable is false. + bool VectorizeEnabled = false; if (Attrs.VectorizeEnable != LoopAttributes::Unspecified || (IsVectorPredicateEnabled && Attrs.VectorizeWidth != 1) || Attrs.VectorizeWidth > 1 || Attrs.VectorizeScalable == LoopAttributes::Enable || (Attrs.VectorizeScalable == LoopAttributes::Disable && Attrs.VectorizeWidth != 1)) { - bool AttrVal = Attrs.VectorizeEnable != LoopAttributes::Disable; + VectorizeEnabled = Attrs.VectorizeEnable != LoopAttributes::Disable; Args.push_back( MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"), ConstantAsMetadata::get(ConstantInt::get( - llvm::Type::getInt1Ty(Ctx), AttrVal))})); + llvm::Type::getInt1Ty(Ctx), VectorizeEnabled))})); } - if (FollowupHasTransforms) - Args.push_back( - createFollowupMetadata("llvm.loop.vectorize.followup_all", Followup)); + // Apply all loop properties to the vectorized loop. + SmallVector<Metadata *, 4> FollowupLoopProperties; + + // If vectorization is not explicitly enabled, the follow-up metadata will be + // directly appended to the list currently being created. In that case, adding + // LoopProperties to FollowupLoopProperties would result in duplication. + if (VectorizeEnabled) + FollowupLoopProperties.append(LoopProperties.begin(), LoopProperties.end()); + + // Don't vectorize an already vectorized loop. + FollowupLoopProperties.push_back( + MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.isvectorized"))); + + bool FollowupHasTransforms = false; + SmallVector<Metadata *, 4> Followup = createUnrollAndJamMetadata( + Attrs, FollowupLoopProperties, FollowupHasTransforms); + + if (FollowupHasTransforms) { + // If vectorization is explicitly enabled, we create a follow-up metadata, + // otherwise directly add the contents of it to Args. + if (VectorizeEnabled) + Args.push_back( + createFollowupMetadata("llvm.loop.vectorize.followup_all", Followup)); + else + Args.append(Followup.begin(), Followup.end()); + } HasUserTransforms = true; return Args; |
