[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper closed 
https://github.com/llvm/llvm-project/pull/228229
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper auto_merge_enabled 
https://github.com/llvm/llvm-project/pull/228229
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/228229

>From 3d7dc9ea1ef17a806cddb3258e30d06f743f1bf9 Mon Sep 17 00:00:00 2001
From: Amr Hesham 
Date: Thu, 1 Oct 2026 20:49:41 +0200
Subject: [PATCH 1/5] [CIR] Add Matrix column major load op

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 41 +++
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  9 
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   | 18 +++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 22 +++---
 clang/test/CIR/CodeGen/matrix.cpp | 36 
 5 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index e450423c12ce24..d8d6305ee262e8 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -6375,6 +6375,47 @@ def CIR_VecSplatOp : CIR_Op<"vec.splat", [
   }];
 }
 
+//===--===//
+// MatrixColumnMajorLoadOp
+//===--===//
+
+def CIR_MatrixColumnMajorLoadOp : CIR_Op<"matrix.column_major_load", [
+  Pure,
+]> {
+  let summary = "Matrix column major load";
+  let description = [{
+  The `cir.matrix.column_major_load` operation provides a representation for
+  the `__builtin_matrix_column_major_load` builtin and corresponds to the
+  `llvm.matrix.column.major.load` intrinsic in LLVM IR.
+
+  This operation performs load any matrix type with a stride to compute
+  the start address of the different columns.
+
+  ```
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i,
+ !cir.matrix<5 x 5 x !cir.double>
+
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i
+ volatile, !cir.matrix<5 x 5 x !cir.double>
+  ```
+  }];
+
+  let arguments = (ins
+CIR_PointerType:$value,
+CIR_IntType:$stride,
+UnitAttr:$is_volatile
+  );
+
+  let results = (outs CIR_MatrixType:$result);
+
+  let assemblyFormat = [{
+$value `:` type($value) `,`
+$stride `:` type($stride)
+(`volatile` $is_volatile^)?
+`,` qualified(type($result)) attr-dict
+  }];
+}
+
 
//===--===//
 // MatrixTransposeOp
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03df..c754c2442f098c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -825,6 +825,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return createVecShuffle(loc, vec1, poison, mask);
   }
 
+  cir::MatrixColumnMajorLoadOp createMatrixColumnMajorLoad(mlir::Location loc,
+   mlir::Type resultTy,
+   mlir::Value value,
+   mlir::Value stride,
+   bool isVolatile) {
+return cir::MatrixColumnMajorLoadOp::create(*this, loc, resultTy, value,
+stride, isVolatile);
+  }
+
   cir::MatrixTransposeOp createMatrixTranspose(mlir::Location loc,
mlir::Value matrix) {
 auto inputTy = mlir::cast(matrix.getType());
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 9203cc0b9f7220..c47165ec153a7e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -2291,7 +2291,23 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 mlir::Value result = builder.createMatrixTranspose(loc, matrix);
 return RValue::get(result);
   }
-  case Builtin::BI__builtin_matrix_column_major_load:
+  case Builtin::BI__builtin_matrix_column_major_load: {
+// Emit everything that isn't dependent on the first parameter type
+mlir::Value stride = emitScalarExpr(e->getArg(3));
+const QualType resultTy = e->getType();
+mlir::Type resultType = convertType(resultTy);
+auto *ptrTy = e->getArg(0)->getType()->getAs();
+assert(ptrTy && "arg0 must be of pointer type");
+bool isVolatile = ptrTy->getPointeeType().isVolatileQualified();
+Address src = emitPointerWithAlignment(e->getArg(0));
+emitNonNullArgCheck(RValue::get(src.emitRawPointer()),
+e->getArg(0)->getType(), e->getArg(0)->getExprLoc(), 
fd,
+0);
+mlir::Value dataPtr = src.emitRawPointer();
+mlir::Value result = builder.createMatrixColumnMajorLoad(
+loc, resultType, dataPtr, stride, isVolatile);
+return RValue::get(result);
+  }
   case 

[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper auto_merge_disabled 
https://github.com/llvm/llvm-project/pull/228229
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/228229

>From 3d7dc9ea1ef17a806cddb3258e30d06f743f1bf9 Mon Sep 17 00:00:00 2001
From: Amr Hesham 
Date: Thu, 1 Oct 2026 20:49:41 +0200
Subject: [PATCH 1/4] [CIR] Add Matrix column major load op

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 41 +++
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  9 
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   | 18 +++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 22 +++---
 clang/test/CIR/CodeGen/matrix.cpp | 36 
 5 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index e450423c12ce24..d8d6305ee262e8 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -6375,6 +6375,47 @@ def CIR_VecSplatOp : CIR_Op<"vec.splat", [
   }];
 }
 
+//===--===//
+// MatrixColumnMajorLoadOp
+//===--===//
+
+def CIR_MatrixColumnMajorLoadOp : CIR_Op<"matrix.column_major_load", [
+  Pure,
+]> {
+  let summary = "Matrix column major load";
+  let description = [{
+  The `cir.matrix.column_major_load` operation provides a representation for
+  the `__builtin_matrix_column_major_load` builtin and corresponds to the
+  `llvm.matrix.column.major.load` intrinsic in LLVM IR.
+
+  This operation performs load any matrix type with a stride to compute
+  the start address of the different columns.
+
+  ```
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i,
+ !cir.matrix<5 x 5 x !cir.double>
+
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i
+ volatile, !cir.matrix<5 x 5 x !cir.double>
+  ```
+  }];
+
+  let arguments = (ins
+CIR_PointerType:$value,
+CIR_IntType:$stride,
+UnitAttr:$is_volatile
+  );
+
+  let results = (outs CIR_MatrixType:$result);
+
+  let assemblyFormat = [{
+$value `:` type($value) `,`
+$stride `:` type($stride)
+(`volatile` $is_volatile^)?
+`,` qualified(type($result)) attr-dict
+  }];
+}
+
 
//===--===//
 // MatrixTransposeOp
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03df..c754c2442f098c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -825,6 +825,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return createVecShuffle(loc, vec1, poison, mask);
   }
 
+  cir::MatrixColumnMajorLoadOp createMatrixColumnMajorLoad(mlir::Location loc,
+   mlir::Type resultTy,
+   mlir::Value value,
+   mlir::Value stride,
+   bool isVolatile) {
+return cir::MatrixColumnMajorLoadOp::create(*this, loc, resultTy, value,
+stride, isVolatile);
+  }
+
   cir::MatrixTransposeOp createMatrixTranspose(mlir::Location loc,
mlir::Value matrix) {
 auto inputTy = mlir::cast(matrix.getType());
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 9203cc0b9f7220..c47165ec153a7e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -2291,7 +2291,23 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 mlir::Value result = builder.createMatrixTranspose(loc, matrix);
 return RValue::get(result);
   }
-  case Builtin::BI__builtin_matrix_column_major_load:
+  case Builtin::BI__builtin_matrix_column_major_load: {
+// Emit everything that isn't dependent on the first parameter type
+mlir::Value stride = emitScalarExpr(e->getArg(3));
+const QualType resultTy = e->getType();
+mlir::Type resultType = convertType(resultTy);
+auto *ptrTy = e->getArg(0)->getType()->getAs();
+assert(ptrTy && "arg0 must be of pointer type");
+bool isVolatile = ptrTy->getPointeeType().isVolatileQualified();
+Address src = emitPointerWithAlignment(e->getArg(0));
+emitNonNullArgCheck(RValue::get(src.emitRawPointer()),
+e->getArg(0)->getType(), e->getArg(0)->getExprLoc(), 
fd,
+0);
+mlir::Value dataPtr = src.emitRawPointer();
+mlir::Value result = builder.createMatrixColumnMajorLoad(
+loc, resultType, dataPtr, stride, isVolatile);
+return RValue::get(result);
+  }
   case 

[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper auto_merge_enabled 
https://github.com/llvm/llvm-project/pull/228229
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/228229

>From 3d7dc9ea1ef17a806cddb3258e30d06f743f1bf9 Mon Sep 17 00:00:00 2001
From: Amr Hesham 
Date: Thu, 1 Oct 2026 20:49:41 +0200
Subject: [PATCH 1/4] [CIR] Add Matrix column major load op

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 41 +++
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  9 
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   | 18 +++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 22 +++---
 clang/test/CIR/CodeGen/matrix.cpp | 36 
 5 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index e450423c12ce24..d8d6305ee262e8 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -6375,6 +6375,47 @@ def CIR_VecSplatOp : CIR_Op<"vec.splat", [
   }];
 }
 
+//===--===//
+// MatrixColumnMajorLoadOp
+//===--===//
+
+def CIR_MatrixColumnMajorLoadOp : CIR_Op<"matrix.column_major_load", [
+  Pure,
+]> {
+  let summary = "Matrix column major load";
+  let description = [{
+  The `cir.matrix.column_major_load` operation provides a representation for
+  the `__builtin_matrix_column_major_load` builtin and corresponds to the
+  `llvm.matrix.column.major.load` intrinsic in LLVM IR.
+
+  This operation performs load any matrix type with a stride to compute
+  the start address of the different columns.
+
+  ```
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i,
+ !cir.matrix<5 x 5 x !cir.double>
+
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i
+ volatile, !cir.matrix<5 x 5 x !cir.double>
+  ```
+  }];
+
+  let arguments = (ins
+CIR_PointerType:$value,
+CIR_IntType:$stride,
+UnitAttr:$is_volatile
+  );
+
+  let results = (outs CIR_MatrixType:$result);
+
+  let assemblyFormat = [{
+$value `:` type($value) `,`
+$stride `:` type($stride)
+(`volatile` $is_volatile^)?
+`,` qualified(type($result)) attr-dict
+  }];
+}
+
 
//===--===//
 // MatrixTransposeOp
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03df..c754c2442f098c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -825,6 +825,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return createVecShuffle(loc, vec1, poison, mask);
   }
 
+  cir::MatrixColumnMajorLoadOp createMatrixColumnMajorLoad(mlir::Location loc,
+   mlir::Type resultTy,
+   mlir::Value value,
+   mlir::Value stride,
+   bool isVolatile) {
+return cir::MatrixColumnMajorLoadOp::create(*this, loc, resultTy, value,
+stride, isVolatile);
+  }
+
   cir::MatrixTransposeOp createMatrixTranspose(mlir::Location loc,
mlir::Value matrix) {
 auto inputTy = mlir::cast(matrix.getType());
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 9203cc0b9f7220..c47165ec153a7e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -2291,7 +2291,23 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 mlir::Value result = builder.createMatrixTranspose(loc, matrix);
 return RValue::get(result);
   }
-  case Builtin::BI__builtin_matrix_column_major_load:
+  case Builtin::BI__builtin_matrix_column_major_load: {
+// Emit everything that isn't dependent on the first parameter type
+mlir::Value stride = emitScalarExpr(e->getArg(3));
+const QualType resultTy = e->getType();
+mlir::Type resultType = convertType(resultTy);
+auto *ptrTy = e->getArg(0)->getType()->getAs();
+assert(ptrTy && "arg0 must be of pointer type");
+bool isVolatile = ptrTy->getPointeeType().isVolatileQualified();
+Address src = emitPointerWithAlignment(e->getArg(0));
+emitNonNullArgCheck(RValue::get(src.emitRawPointer()),
+e->getArg(0)->getType(), e->getArg(0)->getExprLoc(), 
fd,
+0);
+mlir::Value dataPtr = src.emitRawPointer();
+mlir::Value result = builder.createMatrixColumnMajorLoad(
+loc, resultType, dataPtr, stride, isVolatile);
+return RValue::get(result);
+  }
   case 

[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/228229

>From 3d7dc9ea1ef17a806cddb3258e30d06f743f1bf9 Mon Sep 17 00:00:00 2001
From: Amr Hesham 
Date: Thu, 1 Oct 2026 20:49:41 +0200
Subject: [PATCH 1/3] [CIR] Add Matrix column major load op

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 41 +++
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  9 
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   | 18 +++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 22 +++---
 clang/test/CIR/CodeGen/matrix.cpp | 36 
 5 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index e450423c12ce24..d8d6305ee262e8 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -6375,6 +6375,47 @@ def CIR_VecSplatOp : CIR_Op<"vec.splat", [
   }];
 }
 
+//===--===//
+// MatrixColumnMajorLoadOp
+//===--===//
+
+def CIR_MatrixColumnMajorLoadOp : CIR_Op<"matrix.column_major_load", [
+  Pure,
+]> {
+  let summary = "Matrix column major load";
+  let description = [{
+  The `cir.matrix.column_major_load` operation provides a representation for
+  the `__builtin_matrix_column_major_load` builtin and corresponds to the
+  `llvm.matrix.column.major.load` intrinsic in LLVM IR.
+
+  This operation performs load any matrix type with a stride to compute
+  the start address of the different columns.
+
+  ```
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i,
+ !cir.matrix<5 x 5 x !cir.double>
+
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i
+ volatile, !cir.matrix<5 x 5 x !cir.double>
+  ```
+  }];
+
+  let arguments = (ins
+CIR_PointerType:$value,
+CIR_IntType:$stride,
+UnitAttr:$is_volatile
+  );
+
+  let results = (outs CIR_MatrixType:$result);
+
+  let assemblyFormat = [{
+$value `:` type($value) `,`
+$stride `:` type($stride)
+(`volatile` $is_volatile^)?
+`,` qualified(type($result)) attr-dict
+  }];
+}
+
 
//===--===//
 // MatrixTransposeOp
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03df..c754c2442f098c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -825,6 +825,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return createVecShuffle(loc, vec1, poison, mask);
   }
 
+  cir::MatrixColumnMajorLoadOp createMatrixColumnMajorLoad(mlir::Location loc,
+   mlir::Type resultTy,
+   mlir::Value value,
+   mlir::Value stride,
+   bool isVolatile) {
+return cir::MatrixColumnMajorLoadOp::create(*this, loc, resultTy, value,
+stride, isVolatile);
+  }
+
   cir::MatrixTransposeOp createMatrixTranspose(mlir::Location loc,
mlir::Value matrix) {
 auto inputTy = mlir::cast(matrix.getType());
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 9203cc0b9f7220..c47165ec153a7e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -2291,7 +2291,23 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 mlir::Value result = builder.createMatrixTranspose(loc, matrix);
 return RValue::get(result);
   }
-  case Builtin::BI__builtin_matrix_column_major_load:
+  case Builtin::BI__builtin_matrix_column_major_load: {
+// Emit everything that isn't dependent on the first parameter type
+mlir::Value stride = emitScalarExpr(e->getArg(3));
+const QualType resultTy = e->getType();
+mlir::Type resultType = convertType(resultTy);
+auto *ptrTy = e->getArg(0)->getType()->getAs();
+assert(ptrTy && "arg0 must be of pointer type");
+bool isVolatile = ptrTy->getPointeeType().isVolatileQualified();
+Address src = emitPointerWithAlignment(e->getArg(0));
+emitNonNullArgCheck(RValue::get(src.emitRawPointer()),
+e->getArg(0)->getType(), e->getArg(0)->getExprLoc(), 
fd,
+0);
+mlir::Value dataPtr = src.emitRawPointer();
+mlir::Value result = builder.createMatrixColumnMajorLoad(
+loc, resultType, dataPtr, stride, isVolatile);
+return RValue::get(result);
+  }
   case 

[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-03 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/228229

>From 3d7dc9ea1ef17a806cddb3258e30d06f743f1bf9 Mon Sep 17 00:00:00 2001
From: Amr Hesham 
Date: Thu, 1 Oct 2026 20:49:41 +0200
Subject: [PATCH 1/2] [CIR] Add Matrix column major load op

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 41 +++
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  9 
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   | 18 +++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 22 +++---
 clang/test/CIR/CodeGen/matrix.cpp | 36 
 5 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index e450423c12ce24..d8d6305ee262e8 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -6375,6 +6375,47 @@ def CIR_VecSplatOp : CIR_Op<"vec.splat", [
   }];
 }
 
+//===--===//
+// MatrixColumnMajorLoadOp
+//===--===//
+
+def CIR_MatrixColumnMajorLoadOp : CIR_Op<"matrix.column_major_load", [
+  Pure,
+]> {
+  let summary = "Matrix column major load";
+  let description = [{
+  The `cir.matrix.column_major_load` operation provides a representation for
+  the `__builtin_matrix_column_major_load` builtin and corresponds to the
+  `llvm.matrix.column.major.load` intrinsic in LLVM IR.
+
+  This operation performs load any matrix type with a stride to compute
+  the start address of the different columns.
+
+  ```
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i,
+ !cir.matrix<5 x 5 x !cir.double>
+
+  %result = cir.matrix.column_major_load %ptr : , %stride : !u64i
+ volatile, !cir.matrix<5 x 5 x !cir.double>
+  ```
+  }];
+
+  let arguments = (ins
+CIR_PointerType:$value,
+CIR_IntType:$stride,
+UnitAttr:$is_volatile
+  );
+
+  let results = (outs CIR_MatrixType:$result);
+
+  let assemblyFormat = [{
+$value `:` type($value) `,`
+$stride `:` type($stride)
+(`volatile` $is_volatile^)?
+`,` qualified(type($result)) attr-dict
+  }];
+}
+
 
//===--===//
 // MatrixTransposeOp
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03df..c754c2442f098c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -825,6 +825,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return createVecShuffle(loc, vec1, poison, mask);
   }
 
+  cir::MatrixColumnMajorLoadOp createMatrixColumnMajorLoad(mlir::Location loc,
+   mlir::Type resultTy,
+   mlir::Value value,
+   mlir::Value stride,
+   bool isVolatile) {
+return cir::MatrixColumnMajorLoadOp::create(*this, loc, resultTy, value,
+stride, isVolatile);
+  }
+
   cir::MatrixTransposeOp createMatrixTranspose(mlir::Location loc,
mlir::Value matrix) {
 auto inputTy = mlir::cast(matrix.getType());
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 9203cc0b9f7220..c47165ec153a7e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -2291,7 +2291,23 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 mlir::Value result = builder.createMatrixTranspose(loc, matrix);
 return RValue::get(result);
   }
-  case Builtin::BI__builtin_matrix_column_major_load:
+  case Builtin::BI__builtin_matrix_column_major_load: {
+// Emit everything that isn't dependent on the first parameter type
+mlir::Value stride = emitScalarExpr(e->getArg(3));
+const QualType resultTy = e->getType();
+mlir::Type resultType = convertType(resultTy);
+auto *ptrTy = e->getArg(0)->getType()->getAs();
+assert(ptrTy && "arg0 must be of pointer type");
+bool isVolatile = ptrTy->getPointeeType().isVolatileQualified();
+Address src = emitPointerWithAlignment(e->getArg(0));
+emitNonNullArgCheck(RValue::get(src.emitRawPointer()),
+e->getArg(0)->getType(), e->getArg(0)->getExprLoc(), 
fd,
+0);
+mlir::Value dataPtr = src.emitRawPointer();
+mlir::Value result = builder.createMatrixColumnMajorLoad(
+loc, resultType, dataPtr, stride, isVolatile);
+return RValue::get(result);
+  }
   case 

[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-02 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.


https://github.com/llvm/llvm-project/pull/228229
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add Matrix column major load op (PR #228229)

2026-10-02 Thread Erich Keane via cfe-commits


@@ -5232,15 +5232,27 @@ mlir::LogicalResult 
CIRToLLVMVecTernaryOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMMatrixColumnMajorLoadOpLowering::matchAndRewrite(
+cir::MatrixColumnMajorLoadOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  cir::MatrixType resultMatrixTy = op.getResult().getType();
+  mlir::Type resultTy = typeConverter->convertType(resultMatrixTy);
+  rewriter.replaceOpWithNewOp(
+  op, resultTy, adaptor.getValue(), adaptor.getStride(),
+  rewriter.getBoolAttr(op.getIsVolatile()),
+  rewriter.getI32IntegerAttr(resultMatrixTy.getRowNum()),

erichkeane wrote:

Looks like there is a  1<<20 -1 limit in the FE at the moment too, its a 
lang-opts, but not really configurable for some reason.  So *LGTM*.

https://github.com/llvm/llvm-project/pull/228229
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits