Skip to content

[Matrix] Use shape info for StoreInst directly. #142664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
45 changes: 45 additions & 0 deletions llvm/test/Transforms/LowerMatrixIntrinsics/transpose-fold-store.ll
Original file line number Diff line number Diff line change
@@ -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)
Loading