[clang] [llvm] [HLSL][DirectX] Add `transpose` HLSL intrinsic and DXIL lowering of `llvm.matrix.transpose` (PR #186263)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 13 10:23:09 PDT 2026


================
@@ -1135,6 +1136,23 @@ static Value *expandMatrixMultiply(CallInst *Orig) {
   return Result;
 }
 
+// Expand llvm.matrix.transpose as a shufflevector that permutes elements
+// from column-major source to column-major transposed layout.
+// Element (r,c) at index c*Rows + r moves to index r*Cols + c.
+static Value *expandMatrixTranspose(CallInst *Orig) {
+  Value *Mat = Orig->getArgOperand(0);
+  unsigned Rows = cast<ConstantInt>(Orig->getArgOperand(1))->getZExtValue();
+  unsigned Cols = cast<ConstantInt>(Orig->getArgOperand(2))->getZExtValue();
+
+  unsigned NumElts = Rows * Cols;
+  SmallVector<int, 16> Mask(NumElts);
+  for (unsigned I = 0; I < NumElts; ++I)
+    Mask[I] = (I % Cols) * Rows + (I / Cols);
----------------
farzonl wrote:

This should change once we complete this ticket correct? https://github.com/llvm/llvm-project/issues/184906

Wondering if we should link the issue as a TODO?

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


More information about the cfe-commits mailing list