[llvm] 370d017 - [Matrix] Use shape info for StoreInst directly. (#142664)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 01:16:00 PDT 2025


Author: Florian Hahn
Date: 2025-06-04T09:15:57+01:00
New Revision: 370d01765c96da019e7970e875ce525819896464

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

LOG: [Matrix] Use shape info for StoreInst directly. (#142664)

ShapeInfo for the store operand may be dropped, e.g. because the operand
got folded by transpose optimizations to another instruction w/o shape
info. This was exposed by the assertion added in
https://github.com/llvm/llvm-project/pull/142416.

This updates VisitStore to use the shape-info directly from the
instruction, which is in line with the other Visit* functions and
ensures that we won't lose shape info.

PR: https://github.com/llvm/llvm-project/pull/142664

Added: 
    llvm/test/Transforms/LowerMatrixIntrinsics/transpose-fold-store.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 fb5e081acf7c5..1c3d22924795b 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -2117,7 +2117,7 @@ class LowerMatrixIntrinsics {
 
   bool VisitStore(StoreInst *Inst, Value *StoredVal, Value *Ptr,
                   IRBuilder<> &Builder) {
-    auto I = ShapeMap.find(StoredVal);
+    auto I = ShapeMap.find(Inst);
     assert(I != ShapeMap.end() &&
            "must only visit instructions with shape info");
     LowerStore(Inst, StoredVal, Ptr, Inst->getAlign(),

diff  --git a/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-fold-store.ll b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-fold-store.ll
new file mode 100644
index 0000000000000..3a01c516f4b70
--- /dev/null
+++ b/llvm/test/Transforms/LowerMatrixIntrinsics/transpose-fold-store.ll
@@ -0,0 +1,45 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -p lower-matrix-intrinsics -S %s | FileCheck %s
+
+define void @redundant_transpose_of_shuffle(<4 x float> %m, ptr %dst) {
+; CHECK-LABEL: define void @redundant_transpose_of_shuffle(
+; CHECK-SAME: <4 x float> [[M:%.*]], ptr [[DST:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[SHUFFLE:%.*]] = shufflevector <4 x float> [[M]], <4 x float> zeroinitializer, <4 x i32> zeroinitializer
+; CHECK-NEXT:    [[SPLIT:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; CHECK-NEXT:    store <4 x float> [[SPLIT]], ptr [[DST]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %shuffle = shufflevector <4 x float> %m, <4 x float> zeroinitializer, <4 x i32> zeroinitializer
+  %t = tail call <4 x float> @llvm.matrix.transpose.v3f32(<4 x float> %shuffle, i32 1, i32 4)
+  store <4 x float> %t, ptr %dst, align 4
+  ret void
+}
+
+define void @redundant_transpose_of_shuffle_2(<4 x float> %m, ptr %dst) {
+; CHECK-LABEL: define void @redundant_transpose_of_shuffle_2(
+; CHECK-SAME: <4 x float> [[M:%.*]], ptr [[DST:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[SHUFFLE:%.*]] = shufflevector <4 x float> [[M]], <4 x float> zeroinitializer, <4 x i32> zeroinitializer
+; CHECK-NEXT:    [[SPLIT:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> zeroinitializer
+; CHECK-NEXT:    [[SPLIT1:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> <i32 1>
+; CHECK-NEXT:    [[SPLIT2:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> <i32 2>
+; CHECK-NEXT:    [[SPLIT3:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> <i32 3>
+; CHECK-NEXT:    store <1 x float> [[SPLIT]], ptr [[DST]], align 4
+; CHECK-NEXT:    [[VEC_GEP:%.*]] = getelementptr float, ptr [[DST]], i64 1
+; CHECK-NEXT:    store <1 x float> [[SPLIT1]], ptr [[VEC_GEP]], align 4
+; CHECK-NEXT:    [[VEC_GEP4:%.*]] = getelementptr float, ptr [[DST]], i64 2
+; CHECK-NEXT:    store <1 x float> [[SPLIT2]], ptr [[VEC_GEP4]], align 4
+; CHECK-NEXT:    [[VEC_GEP5:%.*]] = getelementptr float, ptr [[DST]], i64 3
+; CHECK-NEXT:    store <1 x float> [[SPLIT3]], ptr [[VEC_GEP5]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %shuffle = shufflevector <4 x float> %m, <4 x float> zeroinitializer, <4 x i32> zeroinitializer
+  %t = tail call <4 x float> @llvm.matrix.transpose.v3f32(<4 x float> %shuffle, i32 4, i32 1)
+  store <4 x float> %t, ptr %dst, align 4
+  ret void
+}
+
+declare <4 x float> @llvm.matrix.transpose.v3f32(<4 x float>, i32, i32)


        


More information about the llvm-commits mailing list