[llvm] [IR] Composable and Extensible Memory Cache Control Hints (PR #181612)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 02:53:31 PDT 2026


================
@@ -5631,6 +5632,66 @@ void Verifier::visitInlineHistoryMetadata(Instruction &I, MDNode *MD) {
   }
 }
 
+void Verifier::visitMemCacheHintMetadata(Instruction &I, MDNode *MD) {
+  Check(I.mayReadOrWriteMemory(),
+        "!mem.cache_hint is only valid on memory operations", &I);
+
+  Check(MD->getNumOperands() % 2 == 0,
+        "!mem.cache_hint must have even number of operands "
+        "(operand_no, hint_node pairs)",
+        MD);
+
+  const auto *CB = dyn_cast<CallBase>(&I);
+  if (CB)
+    Check(CB->getIntrinsicID() != Intrinsic::not_intrinsic,
+          "!mem.cache_hint is not supported on non-intrinsic calls", &I);
+
+  unsigned NumOperands = CB ? CB->arg_size() : I.getNumOperands();
+
+  SmallDenseSet<unsigned, 4> SeenOperandNos;
+
+  // Top-level metadata alternates: i32 operand_no, MDNode hint_node.
+  for (unsigned i = 0; i + 1 < MD->getNumOperands(); i += 2) {
+    auto *OpNoCI = mdconst::dyn_extract<ConstantInt>(MD->getOperand(i));
+    Check(OpNoCI,
+          "!mem.cache_hint operand_no must be an integer constant in pair", MD);
----------------
antoniofrighetto wrote:

Not immediately clear this either, In pair with the MDNode? Or as a first operand of the pair?

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


More information about the llvm-commits mailing list