Skip to content

Commit 370d017

Browse files
authored
[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 #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: #142664
1 parent 991d754 commit 370d017

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ class LowerMatrixIntrinsics {
21172117

21182118
bool VisitStore(StoreInst *Inst, Value *StoredVal, Value *Ptr,
21192119
IRBuilder<> &Builder) {
2120-
auto I = ShapeMap.find(StoredVal);
2120+
auto I = ShapeMap.find(Inst);
21212121
assert(I != ShapeMap.end() &&
21222122
"must only visit instructions with shape info");
21232123
LowerStore(Inst, StoredVal, Ptr, Inst->getAlign(),
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -p lower-matrix-intrinsics -S %s | FileCheck %s
3+
4+
define void @redundant_transpose_of_shuffle(<4 x float> %m, ptr %dst) {
5+
; CHECK-LABEL: define void @redundant_transpose_of_shuffle(
6+
; CHECK-SAME: <4 x float> [[M:%.*]], ptr [[DST:%.*]]) {
7+
; CHECK-NEXT: [[ENTRY:.*:]]
8+
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x float> [[M]], <4 x float> zeroinitializer, <4 x i32> zeroinitializer
9+
; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
10+
; CHECK-NEXT: store <4 x float> [[SPLIT]], ptr [[DST]], align 4
11+
; CHECK-NEXT: ret void
12+
;
13+
entry:
14+
%shuffle = shufflevector <4 x float> %m, <4 x float> zeroinitializer, <4 x i32> zeroinitializer
15+
%t = tail call <4 x float> @llvm.matrix.transpose.v3f32(<4 x float> %shuffle, i32 1, i32 4)
16+
store <4 x float> %t, ptr %dst, align 4
17+
ret void
18+
}
19+
20+
define void @redundant_transpose_of_shuffle_2(<4 x float> %m, ptr %dst) {
21+
; CHECK-LABEL: define void @redundant_transpose_of_shuffle_2(
22+
; CHECK-SAME: <4 x float> [[M:%.*]], ptr [[DST:%.*]]) {
23+
; CHECK-NEXT: [[ENTRY:.*:]]
24+
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x float> [[M]], <4 x float> zeroinitializer, <4 x i32> zeroinitializer
25+
; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> zeroinitializer
26+
; CHECK-NEXT: [[SPLIT1:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> <i32 1>
27+
; CHECK-NEXT: [[SPLIT2:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> <i32 2>
28+
; CHECK-NEXT: [[SPLIT3:%.*]] = shufflevector <4 x float> [[SHUFFLE]], <4 x float> poison, <1 x i32> <i32 3>
29+
; CHECK-NEXT: store <1 x float> [[SPLIT]], ptr [[DST]], align 4
30+
; CHECK-NEXT: [[VEC_GEP:%.*]] = getelementptr float, ptr [[DST]], i64 1
31+
; CHECK-NEXT: store <1 x float> [[SPLIT1]], ptr [[VEC_GEP]], align 4
32+
; CHECK-NEXT: [[VEC_GEP4:%.*]] = getelementptr float, ptr [[DST]], i64 2
33+
; CHECK-NEXT: store <1 x float> [[SPLIT2]], ptr [[VEC_GEP4]], align 4
34+
; CHECK-NEXT: [[VEC_GEP5:%.*]] = getelementptr float, ptr [[DST]], i64 3
35+
; CHECK-NEXT: store <1 x float> [[SPLIT3]], ptr [[VEC_GEP5]], align 4
36+
; CHECK-NEXT: ret void
37+
;
38+
entry:
39+
%shuffle = shufflevector <4 x float> %m, <4 x float> zeroinitializer, <4 x i32> zeroinitializer
40+
%t = tail call <4 x float> @llvm.matrix.transpose.v3f32(<4 x float> %shuffle, i32 4, i32 1)
41+
store <4 x float> %t, ptr %dst, align 4
42+
ret void
43+
}
44+
45+
declare <4 x float> @llvm.matrix.transpose.v3f32(<4 x float>, i32, i32)

0 commit comments

Comments
 (0)