[llvm] f719e7d - [llvm] [MatrixIntrinsics] Add row-major support for llvm.matrix.transpose

via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 12:13:43 PDT 2020


Author: aartbik
Date: 2020-05-28T12:13:32-07:00
New Revision: f719e7d9e7c411b833aa7f40e7a2a6c891def843

URL: https://github.com/llvm/llvm-project/commit/f719e7d9e7c411b833aa7f40e7a2a6c891def843
DIFF: https://github.com/llvm/llvm-project/commit/f719e7d9e7c411b833aa7f40e7a2a6c891def843.diff

LOG: [llvm] [MatrixIntrinsics] Add row-major support for llvm.matrix.transpose

Summary:
Only column-major was supported so far. This adds row-major support as well.
Note that we probably also want very efficient SIMD implementations for the
various target platforms.

Bug:
https://bugs.llvm.org/show_bug.cgi?id=46085

Reviewers: nicolasvasilache, reidtatge, bkramer, fhahn, ftynse, andydavis1, craig.topper, dcaballe, mehdi_amini, anemet

Reviewed By: fhahn

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80673

Added: 
    llvm/test/Transforms/LowerMatrixIntrinsics/transpose-double-row-major.ll
    llvm/test/Transforms/LowerMatrixIntrinsics/transpose-float-row-major.ll
    llvm/test/Transforms/LowerMatrixIntrinsics/transpose-i32-row-major.ll

Modified: 
    llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
index 45709cb65503..801069bb97b4 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -1294,24 +1294,24 @@ class LowerMatrixIntrinsics {
     VectorType *VectorTy = cast<VectorType>(InputVal->getType());
     ShapeInfo ArgShape(Inst->getArgOperand(1), Inst->getArgOperand(2));
     MatrixTy InputMatrix = getMatrix(InputVal, ArgShape, Builder);
-    assert(InputMatrix.isColumnMajor() &&
-           "Row-major code-gen not supported yet!");
-
-    for (unsigned Row = 0; Row < ArgShape.NumRows; ++Row) {
-      // Build a single column vector for this row. First initialize it.
-      Value *ResultColumn = UndefValue::get(
-          VectorType::get(VectorTy->getElementType(), ArgShape.NumColumns));
-
-      // Go through the elements of this row and insert it into the resulting
-      // column vector.
-      for (auto C : enumerate(InputMatrix.columns())) {
-        Value *Elt = Builder.CreateExtractElement(C.value(), Row);
-        // We insert at index Column since that is the row index after the
-        // transpose.
-        ResultColumn =
-            Builder.CreateInsertElement(ResultColumn, Elt, C.index());
+
+    const unsigned NewNumVecs =
+        InputMatrix.isColumnMajor() ? ArgShape.NumRows : ArgShape.NumColumns;
+    const unsigned NewNumElts =
+        InputMatrix.isColumnMajor() ? ArgShape.NumColumns : ArgShape.NumRows;
+
+    for (unsigned I = 0; I < NewNumVecs; ++I) {
+      // Build a single result vector. First initialize it.
+      Value *ResultVector = UndefValue::get(
+          VectorType::get(VectorTy->getElementType(), NewNumElts));
+      // Go through the old elements and insert it into the resulting vector.
+      for (auto J : enumerate(InputMatrix.vectors())) {
+        Value *Elt = Builder.CreateExtractElement(J.value(), I);
+        // Row and column indices are transposed.
+        ResultVector =
+            Builder.CreateInsertElement(ResultVector, Elt, J.index());
       }
-      Result.addVector(ResultColumn);
+      Result.addVector(ResultVector);
     }
 
     // TODO: Improve estimate of operations needed for transposes. Currently we

diff  --git a/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-double-row-major.ll b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-double-row-major.ll
new file mode 100644
index 000000000000..5d607f4b57f1
--- /dev/null
+++ b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-double-row-major.ll
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -lower-matrix-intrinsics -matrix-default-layout=row-major -S < %s | FileCheck --check-prefix=RM %s
+
+define <8 x double> @transpose(<8 x double> %a) {
+; RM-LABEL: @transpose(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <8 x double> [[A:%.*]], <8 x double> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <4 x double> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <2 x double> undef, double [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <2 x double> [[TMP1]], double [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <4 x double> [[SPLIT]], i64 1
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <2 x double> undef, double [[TMP4]], i64 0
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 1
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <2 x double> [[TMP5]], double [[TMP6]], i64 1
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <4 x double> [[SPLIT]], i64 2
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <2 x double> undef, double [[TMP8]], i64 0
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 2
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <2 x double> [[TMP9]], double [[TMP10]], i64 1
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <4 x double> [[SPLIT]], i64 3
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <2 x double> undef, double [[TMP12]], i64 0
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 3
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <2 x double> [[TMP13]], double [[TMP14]], i64 1
+; RM-NEXT:    [[TMP16:%.*]] = shufflevector <2 x double> [[TMP3]], <2 x double> [[TMP7]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[TMP17:%.*]] = shufflevector <2 x double> [[TMP11]], <2 x double> [[TMP15]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[TMP18:%.*]] = shufflevector <4 x double> [[TMP16]], <4 x double> [[TMP17]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    ret <8 x double> [[TMP18]]
+;
+entry:
+  %c  = call <8 x double> @llvm.matrix.transpose(<8 x double> %a, i32 2, i32 4)
+  ret <8 x double> %c
+}
+
+declare <8 x double> @llvm.matrix.transpose(<8 x double>, i32, i32)
+
+define <8 x double> @transpose_single_column(<8 x double> %a) {
+; RM-LABEL: @transpose_single_column(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <8 x double> [[A:%.*]], <8 x double> undef, <1 x i32> zeroinitializer
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <1 x i32> <i32 1>
+; RM-NEXT:    [[SPLIT2:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <1 x i32> <i32 2>
+; RM-NEXT:    [[SPLIT3:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <1 x i32> <i32 3>
+; RM-NEXT:    [[SPLIT4:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <1 x i32> <i32 4>
+; RM-NEXT:    [[SPLIT5:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <1 x i32> <i32 5>
+; RM-NEXT:    [[SPLIT6:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <1 x i32> <i32 6>
+; RM-NEXT:    [[SPLIT7:%.*]] = shufflevector <8 x double> [[A]], <8 x double> undef, <1 x i32> <i32 7>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <1 x double> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <8 x double> undef, double [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <1 x double> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <8 x double> [[TMP1]], double [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <1 x double> [[SPLIT2]], i64 0
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <8 x double> [[TMP3]], double [[TMP4]], i64 2
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <1 x double> [[SPLIT3]], i64 0
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <8 x double> [[TMP5]], double [[TMP6]], i64 3
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <1 x double> [[SPLIT4]], i64 0
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <8 x double> [[TMP7]], double [[TMP8]], i64 4
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <1 x double> [[SPLIT5]], i64 0
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <8 x double> [[TMP9]], double [[TMP10]], i64 5
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <1 x double> [[SPLIT6]], i64 0
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <8 x double> [[TMP11]], double [[TMP12]], i64 6
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <1 x double> [[SPLIT7]], i64 0
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <8 x double> [[TMP13]], double [[TMP14]], i64 7
+; RM-NEXT:    ret <8 x double> [[TMP15]]
+;
+entry:
+  %c  = call <8 x double> @llvm.matrix.transpose(<8 x double> %a, i32 8, i32 1)
+  ret <8 x double> %c
+}
+
+declare <12 x double> @llvm.matrix.transpose.v12f64(<12 x double>, i32, i32)
+
+define <12 x double> @transpose_double_3x4(<12 x double> %a) {
+; RM-LABEL: @transpose_double_3x4(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <12 x double> [[A:%.*]], <12 x double> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <12 x double> [[A]], <12 x double> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    [[SPLIT2:%.*]] = shufflevector <12 x double> [[A]], <12 x double> undef, <4 x i32> <i32 8, i32 9, i32 10, i32 11>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <4 x double> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <3 x double> undef, double [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <3 x double> [[TMP1]], double [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <4 x double> [[SPLIT2]], i64 0
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <3 x double> [[TMP3]], double [[TMP4]], i64 2
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <4 x double> [[SPLIT]], i64 1
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <3 x double> undef, double [[TMP6]], i64 0
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 1
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <3 x double> [[TMP7]], double [[TMP8]], i64 1
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <4 x double> [[SPLIT2]], i64 1
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <3 x double> [[TMP9]], double [[TMP10]], i64 2
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <4 x double> [[SPLIT]], i64 2
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <3 x double> undef, double [[TMP12]], i64 0
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 2
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <3 x double> [[TMP13]], double [[TMP14]], i64 1
+; RM-NEXT:    [[TMP16:%.*]] = extractelement <4 x double> [[SPLIT2]], i64 2
+; RM-NEXT:    [[TMP17:%.*]] = insertelement <3 x double> [[TMP15]], double [[TMP16]], i64 2
+; RM-NEXT:    [[TMP18:%.*]] = extractelement <4 x double> [[SPLIT]], i64 3
+; RM-NEXT:    [[TMP19:%.*]] = insertelement <3 x double> undef, double [[TMP18]], i64 0
+; RM-NEXT:    [[TMP20:%.*]] = extractelement <4 x double> [[SPLIT1]], i64 3
+; RM-NEXT:    [[TMP21:%.*]] = insertelement <3 x double> [[TMP19]], double [[TMP20]], i64 1
+; RM-NEXT:    [[TMP22:%.*]] = extractelement <4 x double> [[SPLIT2]], i64 3
+; RM-NEXT:    [[TMP23:%.*]] = insertelement <3 x double> [[TMP21]], double [[TMP22]], i64 2
+; RM-NEXT:    [[TMP24:%.*]] = shufflevector <3 x double> [[TMP5]], <3 x double> [[TMP11]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; RM-NEXT:    [[TMP25:%.*]] = shufflevector <3 x double> [[TMP17]], <3 x double> [[TMP23]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; RM-NEXT:    [[TMP26:%.*]] = shufflevector <6 x double> [[TMP24]], <6 x double> [[TMP25]], <12 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11>
+; RM-NEXT:    ret <12 x double> [[TMP26]]
+;
+entry:
+  %c  = call <12 x double> @llvm.matrix.transpose.v12f64(<12 x double> %a, i32 3, i32 4)
+  ret <12 x double> %c
+}

diff  --git a/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-float-row-major.ll b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-float-row-major.ll
new file mode 100644
index 000000000000..8a9bf5ae3be4
--- /dev/null
+++ b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-float-row-major.ll
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -lower-matrix-intrinsics -matrix-default-layout=row-major -S < %s | FileCheck --check-prefix=RM %s
+
+define <8 x float> @transpose(<8 x float> %a) {
+; RM-LABEL: @transpose(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <8 x float> [[A:%.*]], <8 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <4 x float> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <2 x float> undef, float [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <2 x float> [[TMP1]], float [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <4 x float> [[SPLIT]], i64 1
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <2 x float> undef, float [[TMP4]], i64 0
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 1
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <2 x float> [[TMP5]], float [[TMP6]], i64 1
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <4 x float> [[SPLIT]], i64 2
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <2 x float> undef, float [[TMP8]], i64 0
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 2
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <2 x float> [[TMP9]], float [[TMP10]], i64 1
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <4 x float> [[SPLIT]], i64 3
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <2 x float> undef, float [[TMP12]], i64 0
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 3
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <2 x float> [[TMP13]], float [[TMP14]], i64 1
+; RM-NEXT:    [[TMP16:%.*]] = shufflevector <2 x float> [[TMP3]], <2 x float> [[TMP7]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[TMP17:%.*]] = shufflevector <2 x float> [[TMP11]], <2 x float> [[TMP15]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[TMP18:%.*]] = shufflevector <4 x float> [[TMP16]], <4 x float> [[TMP17]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    ret <8 x float> [[TMP18]]
+;
+entry:
+  %c  = call <8 x float> @llvm.matrix.transpose(<8 x float> %a, i32 2, i32 4)
+  ret <8 x float> %c
+}
+
+declare <8 x float> @llvm.matrix.transpose(<8 x float>, i32, i32)
+
+define <8 x float> @transpose_single_column(<8 x float> %a) {
+; RM-LABEL: @transpose_single_column(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <8 x float> [[A:%.*]], <8 x float> undef, <1 x i32> zeroinitializer
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <1 x i32> <i32 1>
+; RM-NEXT:    [[SPLIT2:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <1 x i32> <i32 2>
+; RM-NEXT:    [[SPLIT3:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <1 x i32> <i32 3>
+; RM-NEXT:    [[SPLIT4:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <1 x i32> <i32 4>
+; RM-NEXT:    [[SPLIT5:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <1 x i32> <i32 5>
+; RM-NEXT:    [[SPLIT6:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <1 x i32> <i32 6>
+; RM-NEXT:    [[SPLIT7:%.*]] = shufflevector <8 x float> [[A]], <8 x float> undef, <1 x i32> <i32 7>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <1 x float> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <8 x float> undef, float [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <1 x float> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <8 x float> [[TMP1]], float [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <1 x float> [[SPLIT2]], i64 0
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <8 x float> [[TMP3]], float [[TMP4]], i64 2
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <1 x float> [[SPLIT3]], i64 0
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <8 x float> [[TMP5]], float [[TMP6]], i64 3
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <1 x float> [[SPLIT4]], i64 0
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <8 x float> [[TMP7]], float [[TMP8]], i64 4
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <1 x float> [[SPLIT5]], i64 0
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <8 x float> [[TMP9]], float [[TMP10]], i64 5
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <1 x float> [[SPLIT6]], i64 0
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <8 x float> [[TMP11]], float [[TMP12]], i64 6
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <1 x float> [[SPLIT7]], i64 0
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <8 x float> [[TMP13]], float [[TMP14]], i64 7
+; RM-NEXT:    ret <8 x float> [[TMP15]]
+;
+entry:
+  %c  = call <8 x float> @llvm.matrix.transpose(<8 x float> %a, i32 8, i32 1)
+  ret <8 x float> %c
+}
+
+declare <12 x float> @llvm.matrix.transpose.v12f32(<12 x float>, i32, i32)
+
+define <12 x float> @transpose_float_3x4(<12 x float> %a) {
+; RM-LABEL: @transpose_float_3x4(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <12 x float> [[A:%.*]], <12 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <12 x float> [[A]], <12 x float> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    [[SPLIT2:%.*]] = shufflevector <12 x float> [[A]], <12 x float> undef, <4 x i32> <i32 8, i32 9, i32 10, i32 11>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <4 x float> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <3 x float> undef, float [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <3 x float> [[TMP1]], float [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <4 x float> [[SPLIT2]], i64 0
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <3 x float> [[TMP3]], float [[TMP4]], i64 2
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <4 x float> [[SPLIT]], i64 1
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <3 x float> undef, float [[TMP6]], i64 0
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 1
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <3 x float> [[TMP7]], float [[TMP8]], i64 1
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <4 x float> [[SPLIT2]], i64 1
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <3 x float> [[TMP9]], float [[TMP10]], i64 2
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <4 x float> [[SPLIT]], i64 2
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <3 x float> undef, float [[TMP12]], i64 0
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 2
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <3 x float> [[TMP13]], float [[TMP14]], i64 1
+; RM-NEXT:    [[TMP16:%.*]] = extractelement <4 x float> [[SPLIT2]], i64 2
+; RM-NEXT:    [[TMP17:%.*]] = insertelement <3 x float> [[TMP15]], float [[TMP16]], i64 2
+; RM-NEXT:    [[TMP18:%.*]] = extractelement <4 x float> [[SPLIT]], i64 3
+; RM-NEXT:    [[TMP19:%.*]] = insertelement <3 x float> undef, float [[TMP18]], i64 0
+; RM-NEXT:    [[TMP20:%.*]] = extractelement <4 x float> [[SPLIT1]], i64 3
+; RM-NEXT:    [[TMP21:%.*]] = insertelement <3 x float> [[TMP19]], float [[TMP20]], i64 1
+; RM-NEXT:    [[TMP22:%.*]] = extractelement <4 x float> [[SPLIT2]], i64 3
+; RM-NEXT:    [[TMP23:%.*]] = insertelement <3 x float> [[TMP21]], float [[TMP22]], i64 2
+; RM-NEXT:    [[TMP24:%.*]] = shufflevector <3 x float> [[TMP5]], <3 x float> [[TMP11]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; RM-NEXT:    [[TMP25:%.*]] = shufflevector <3 x float> [[TMP17]], <3 x float> [[TMP23]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; RM-NEXT:    [[TMP26:%.*]] = shufflevector <6 x float> [[TMP24]], <6 x float> [[TMP25]], <12 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11>
+; RM-NEXT:    ret <12 x float> [[TMP26]]
+;
+entry:
+  %c  = call <12 x float> @llvm.matrix.transpose.v12f32(<12 x float> %a, i32 3, i32 4)
+  ret <12 x float> %c
+}

diff  --git a/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-i32-row-major.ll b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-i32-row-major.ll
new file mode 100644
index 000000000000..2f23d5fd8fec
--- /dev/null
+++ b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-i32-row-major.ll
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -lower-matrix-intrinsics -matrix-default-layout=row-major -S < %s | FileCheck --check-prefix=RM %s
+
+define <8 x i32> @transpose(<8 x i32> %a) {
+; RM-LABEL: @transpose(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <8 x i32> [[A:%.*]], <8 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <2 x i32> undef, i32 [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 1
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <2 x i32> undef, i32 [[TMP4]], i64 0
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 1
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <2 x i32> [[TMP5]], i32 [[TMP6]], i64 1
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 2
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <2 x i32> undef, i32 [[TMP8]], i64 0
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 2
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <2 x i32> [[TMP9]], i32 [[TMP10]], i64 1
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 3
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <2 x i32> undef, i32 [[TMP12]], i64 0
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 3
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <2 x i32> [[TMP13]], i32 [[TMP14]], i64 1
+; RM-NEXT:    [[TMP16:%.*]] = shufflevector <2 x i32> [[TMP3]], <2 x i32> [[TMP7]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[TMP17:%.*]] = shufflevector <2 x i32> [[TMP11]], <2 x i32> [[TMP15]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[TMP18:%.*]] = shufflevector <4 x i32> [[TMP16]], <4 x i32> [[TMP17]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    ret <8 x i32> [[TMP18]]
+;
+entry:
+  %c  = call <8 x i32> @llvm.matrix.transpose(<8 x i32> %a, i32 2, i32 4)
+  ret <8 x i32> %c
+}
+
+declare <8 x i32> @llvm.matrix.transpose(<8 x i32>, i32, i32)
+
+define <8 x i32> @transpose_single_column(<8 x i32> %a) {
+; RM-LABEL: @transpose_single_column(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <8 x i32> [[A:%.*]], <8 x i32> undef, <1 x i32> zeroinitializer
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <1 x i32> <i32 1>
+; RM-NEXT:    [[SPLIT2:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <1 x i32> <i32 2>
+; RM-NEXT:    [[SPLIT3:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <1 x i32> <i32 3>
+; RM-NEXT:    [[SPLIT4:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <1 x i32> <i32 4>
+; RM-NEXT:    [[SPLIT5:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <1 x i32> <i32 5>
+; RM-NEXT:    [[SPLIT6:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <1 x i32> <i32 6>
+; RM-NEXT:    [[SPLIT7:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> undef, <1 x i32> <i32 7>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <1 x i32> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <8 x i32> undef, i32 [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <1 x i32> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <8 x i32> [[TMP1]], i32 [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <1 x i32> [[SPLIT2]], i64 0
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <8 x i32> [[TMP3]], i32 [[TMP4]], i64 2
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <1 x i32> [[SPLIT3]], i64 0
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <8 x i32> [[TMP5]], i32 [[TMP6]], i64 3
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <1 x i32> [[SPLIT4]], i64 0
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <8 x i32> [[TMP7]], i32 [[TMP8]], i64 4
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <1 x i32> [[SPLIT5]], i64 0
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <8 x i32> [[TMP9]], i32 [[TMP10]], i64 5
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <1 x i32> [[SPLIT6]], i64 0
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <8 x i32> [[TMP11]], i32 [[TMP12]], i64 6
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <1 x i32> [[SPLIT7]], i64 0
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <8 x i32> [[TMP13]], i32 [[TMP14]], i64 7
+; RM-NEXT:    ret <8 x i32> [[TMP15]]
+;
+entry:
+  %c  = call <8 x i32> @llvm.matrix.transpose(<8 x i32> %a, i32 8, i32 1)
+  ret <8 x i32> %c
+}
+
+declare <12 x i32> @llvm.matrix.transpose.v12i32(<12 x i32>, i32, i32)
+
+define <12 x i32> @transpose_i32_3x4(<12 x i32> %a) {
+; RM-LABEL: @transpose_i32_3x4(
+; RM-NEXT:  entry:
+; RM-NEXT:    [[SPLIT:%.*]] = shufflevector <12 x i32> [[A:%.*]], <12 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; RM-NEXT:    [[SPLIT1:%.*]] = shufflevector <12 x i32> [[A]], <12 x i32> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+; RM-NEXT:    [[SPLIT2:%.*]] = shufflevector <12 x i32> [[A]], <12 x i32> undef, <4 x i32> <i32 8, i32 9, i32 10, i32 11>
+; RM-NEXT:    [[TMP0:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 0
+; RM-NEXT:    [[TMP1:%.*]] = insertelement <3 x i32> undef, i32 [[TMP0]], i64 0
+; RM-NEXT:    [[TMP2:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 0
+; RM-NEXT:    [[TMP3:%.*]] = insertelement <3 x i32> [[TMP1]], i32 [[TMP2]], i64 1
+; RM-NEXT:    [[TMP4:%.*]] = extractelement <4 x i32> [[SPLIT2]], i64 0
+; RM-NEXT:    [[TMP5:%.*]] = insertelement <3 x i32> [[TMP3]], i32 [[TMP4]], i64 2
+; RM-NEXT:    [[TMP6:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 1
+; RM-NEXT:    [[TMP7:%.*]] = insertelement <3 x i32> undef, i32 [[TMP6]], i64 0
+; RM-NEXT:    [[TMP8:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 1
+; RM-NEXT:    [[TMP9:%.*]] = insertelement <3 x i32> [[TMP7]], i32 [[TMP8]], i64 1
+; RM-NEXT:    [[TMP10:%.*]] = extractelement <4 x i32> [[SPLIT2]], i64 1
+; RM-NEXT:    [[TMP11:%.*]] = insertelement <3 x i32> [[TMP9]], i32 [[TMP10]], i64 2
+; RM-NEXT:    [[TMP12:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 2
+; RM-NEXT:    [[TMP13:%.*]] = insertelement <3 x i32> undef, i32 [[TMP12]], i64 0
+; RM-NEXT:    [[TMP14:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 2
+; RM-NEXT:    [[TMP15:%.*]] = insertelement <3 x i32> [[TMP13]], i32 [[TMP14]], i64 1
+; RM-NEXT:    [[TMP16:%.*]] = extractelement <4 x i32> [[SPLIT2]], i64 2
+; RM-NEXT:    [[TMP17:%.*]] = insertelement <3 x i32> [[TMP15]], i32 [[TMP16]], i64 2
+; RM-NEXT:    [[TMP18:%.*]] = extractelement <4 x i32> [[SPLIT]], i64 3
+; RM-NEXT:    [[TMP19:%.*]] = insertelement <3 x i32> undef, i32 [[TMP18]], i64 0
+; RM-NEXT:    [[TMP20:%.*]] = extractelement <4 x i32> [[SPLIT1]], i64 3
+; RM-NEXT:    [[TMP21:%.*]] = insertelement <3 x i32> [[TMP19]], i32 [[TMP20]], i64 1
+; RM-NEXT:    [[TMP22:%.*]] = extractelement <4 x i32> [[SPLIT2]], i64 3
+; RM-NEXT:    [[TMP23:%.*]] = insertelement <3 x i32> [[TMP21]], i32 [[TMP22]], i64 2
+; RM-NEXT:    [[TMP24:%.*]] = shufflevector <3 x i32> [[TMP5]], <3 x i32> [[TMP11]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; RM-NEXT:    [[TMP25:%.*]] = shufflevector <3 x i32> [[TMP17]], <3 x i32> [[TMP23]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; RM-NEXT:    [[TMP26:%.*]] = shufflevector <6 x i32> [[TMP24]], <6 x i32> [[TMP25]], <12 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11>
+; RM-NEXT:    ret <12 x i32> [[TMP26]]
+;
+entry:
+  %c  = call <12 x i32> @llvm.matrix.transpose.v12i32(<12 x i32> %a, i32 3, i32 4)
+  ret <12 x i32> %c
+}


        


More information about the llvm-commits mailing list