[clang] [flang] [llvm] [mlir] [polly] Enforce single-operand form for llvm.loop.vectorize metadata (PR #210932)
Michael Kruse via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 30 07:22:21 PDT 2026
================
@@ -250,6 +250,26 @@ void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *StringMD,
TheLoop->setLoopID(NewLoopID);
}
+void llvm::addStringMetadataToLoop(Loop *TheLoop, StringRef StringMD) {
+ LLVMContext &Context = TheLoop->getHeader()->getContext();
+ SmallVector<Metadata *, 4> MDs(1);
+ // Retain existing metadata, skipping a name-only node with the same string.
+ if (MDNode *LoopID = TheLoop->getLoopID())
+ for (const MDOperand &Op : drop_begin(LoopID->operands())) {
+ MDNode *Node = cast<MDNode>(Op);
+ if (Node->getNumOperands() == 1)
+ if (auto *S = dyn_cast<MDString>(Node->getOperand(0)))
+ if (S->getString() == StringMD)
+ return;
+ MDs.push_back(Node);
+ }
+ MDs.push_back(MDNode::get(Context, {MDString::get(Context, StringMD)}));
+ MDNode *NewLoopID = MDNode::get(Context, MDs);
+ // Set operand 0 to refer to the loop id itself.
----------------
Meinersbur wrote:
```suggestion
// LoopIDs refer to themselves to make each of them unique
```
No description of what that line does is necessary; explain why it is done
https://github.com/llvm/llvm-project/pull/210932
More information about the cfe-commits
mailing list