[clang] [lldb] [llvm] [OpenCL][Clang] Add support for cooperative matrix extension (PR #221328)

Shyam Manohar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 08:02:22 PDT 2026


================
@@ -17332,6 +17353,336 @@ bool Sema::BuiltinNonDeterministicValue(CallExpr *TheCall) {
   return false;
 }
 
+// Check coop_mat_load/store buffer pointer.
+bool Sema::CheckCoopMatrixLoadStorePtr(CallExpr *TheCall, unsigned PtrArgIdx) {
+  bool ArgError = false;
+  Expr *PtrExpr = TheCall->getArg(PtrArgIdx);
+  ExprResult PtrConv = DefaultFunctionArrayLvalueConversion(PtrExpr);
+  if (PtrConv.isInvalid())
+    return true;
+  PtrExpr = PtrConv.get();
+  TheCall->setArg(PtrArgIdx, PtrExpr);
+
+  auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
+  QualType ElementTy;
+  if (!PtrTy) {
+    ArgError = true;
+  } else {
+    ElementTy = PtrTy->getPointeeType().getUnqualifiedType();
+    if (!CooperativeMatrixType::isValidElementType(ElementTy)) {
+      ArgError = true;
+    }
+  }
+
+  if (ArgError) {
+    Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+        << PtrArgIdx + 1 << 0 << /* pointer to element ty */ 5 << /* no fp */ 0
+        << PtrExpr->getType();
+  }
+
+  return ArgError;
+}
+
+// Check coop_mat_load/store matrix element has same type with buffer pointer.
+bool Sema::CheckCoopMatrixLoadStoreElementType(QualType MatrixType,
+                                               QualType BufferType,
+                                               SourceLocation MatrixLoc) {
+  auto *MTy = MatrixType->getAs<CooperativeMatrixType>();
+  if (!MTy) {
+    Diag(MatrixLoc, diag::err_coop_matrix_arg);
+    return true;
+  }
+
+  assert(isa<PointerType>(BufferType));
+  auto *PTy = BufferType->castAs<PointerType>();
+
+  if (MTy->getElementType().getUnqualifiedType() !=
----------------
shyammanohar wrote:

Is there any plan to support pointer pointee types that differ from the matrix element type. e.g. uvec4* / uint4* buffer backing an f16 cooperative matrix ? The current CheckCoopMatrixLoadStoreElementType check requires exact equality, and the same restriction applies to both load and store paths so this pattern doesn't appear possible with the current PR. SPV_KHR_cooperative_matrix spec allows it.

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


More information about the llvm-commits mailing list