[polly] [Polly] Add vectorize metadata to loops identified as vectorizable by polly (PR #113994)

Karthika Devi C via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 01:46:46 PST 2024


================
@@ -233,6 +238,30 @@ static bool generateCode(Scop &S, IslAstInfo &AI, LoopInfo &LI,
   NodeBuilder.allocateNewArrays(StartExitBlocks);
   Annotator.buildAliasScopes(S);
 
+  // The code below annotates the "llvm.loop.vectorize.enable" to false
+  // for the code flow taken when RTCs fail. Because we don't want the
+  // Loop Vectorizer to come in later and vectorize the original fall back
+  // loop when 'polly-annotate-metadata-vectorize' is passed.
+  if (PollyVectorizeMetadata) {
+    LLVMContext &Ctx = S.getFunction().getContext();
+    for (Loop *L : LI.getLoopsInPreorder()) {
+      if (!L || !S.contains(L))
+        continue;
+      MDNode *LoopID = L->getLoopID();
+      SmallVector<Metadata *, 3> Args;
+      if (LoopID)
+        for (unsigned i = 0, e = LoopID->getNumOperands(); i != e; ++i)
+          Args.push_back(LoopID->getOperand(i));
+      else
+        Args.push_back(nullptr);
+
+      Annotator.addVectorizeMetadata(Ctx, &Args, false);
+      MDNode *NewLoopID = MDNode::get(Ctx, Args);
+      NewLoopID->replaceOperandWith(0, NewLoopID);
+      L->setLoopID(NewLoopID);
+    }
----------------
kartcq wrote:

A small query here ..
Using addStringMetadataToLoop API makes the value get set as i32.
Something like
`!2 = !{!"llvm.loop.vectorize.enable", i32 0}`
Though the behavior is same, Is it okay, as the value should be i1 according to [LangRef.rst](https://github.com/llvm/llvm-project/blob/c6f3b7bcd0596d30f8dabecdfb9e44f9a07b6e4c/llvm/docs/LangRef.rst#L7325)?

https://github.com/llvm/llvm-project/pull/113994


More information about the llvm-commits mailing list