1; REQUIRES: aarch64-registered-target
2
3; This test needs to be target specific due to the cost estimate in the output.
4
5; RUN: opt -passes=lower-matrix-intrinsics -pass-remarks=lower-matrix-intrinsics -mtriple=arm64-apple-iphoneos < %s 2>&1 | FileCheck %s
6
7; CHECK-LABEL: remark: test.h:40:20: Lowered with 6 stores, 6 loads, 24 compute ops
8; CHECK-NEXT: store(
9; CHECK-NEXT:  transpose.2x6.double(load(addr %A)),
10; CHECK-NEXT:  addr %B)
11define void @transpose(<12 x double>* %A, <12 x double>* %B) !dbg !23 {
12  %load = load <12 x double>, <12 x double>* %A, !dbg !24
13  %t = call <12 x double> @llvm.matrix.transpose.v12f64.v12f64(<12 x double> %load, i32 2, i32 6), !dbg !24
14  store <12 x double> %t, <12 x double>* %B, !dbg !24
15  ret void
16}
17
18; CHECK-LABEL: remark: test.h:50:20: Lowered with 2 stores, 12 loads, 22 compute ops
19; CHECK-NEXT:  store(
20; CHECK-NEXT:   multiply.2x6.6x2.double(
21; CHECK-NEXT:    load(addr %A),
22; CHECK-NEXT:    load(addr %B)),
23; CHECK-NEXT:   addr %C)
24define void @multiply(<12 x double>* %A, <12 x double>* %B, <4 x double>* %C) !dbg !25 {
25  %A.matrix = load <12 x double>, <12 x double>* %A, !dbg !26
26  %B.matrix = load <12 x double>, <12 x double>* %B, !dbg !26
27  %t = call <4 x double> @llvm.matrix.multiply(<12 x double> %A.matrix, <12 x double> %B.matrix, i32 2, i32 6, i32 2), !dbg !26
28  store <4 x double> %t, <4 x double>* %C, !dbg !26
29  ret void
30}
31
32; CHECK-LABEL: remark: test.h:60:20: Lowered with 6 stores, 6 loads, 0 compute ops
33; CHECK-NEXT:  store(
34; CHECK-NEXT:   column.major.load.3x3.double(addr %A, 5),
35; CHECK-NEXT:   addr %B)
36define void @column.major.load(double* %A, <9 x double>* %B) !dbg !27 {
37  %A.matrix = call <9 x double> @llvm.matrix.column.major.load(double* %A, i64 5, i1 false, i32 3, i32 3), !dbg !28
38  store <9 x double> %A.matrix, <9 x double>* %B, !dbg !28
39  ret void
40}
41
42; CHECK-LABEL: remark: test.h:70:20: Lowered with 6 stores, 6 loads, 0 compute ops
43; CHECK-NEXT:  column.major.store.3x3.double(
44; CHECK-NEXT:   column.major.load.3x3.double(addr %A, 5),
45; CHECK-NEXT:   addr %B,
46; CHECK-NEXT:   10)
47define void @column.major.store(double* %A, double* %B) !dbg !29 {
48  %A.matrix = call <9 x double> @llvm.matrix.column.major.load(double* %A, i64 5, i1 false, i32 3, i32 3), !dbg !30
49  call void @llvm.matrix.column.major.store(<9 x double> %A.matrix, double* %B, i64 10, i1 false, i32 3, i32 3), !dbg !30
50  ret void
51}
52
53; CHECK-LABEL: remark: test.h:80:20: Lowered with 6 stores, 6 loads, 12 compute ops
54; CHECK-NEXT:  column.major.store.3x3.double(
55; CHECK-NEXT:   fmul(
56; CHECK-NEXT:    fadd(
57; CHECK-NEXT:     column.major.load.3x3.double(addr %A, 5)
58; CHECK-NEXT:     (reused) column.major.load.3x3.double(addr %A, 5)),
59; CHECK-NEXT:    (reused) column.major.load.3x3.double(addr %A, 5)),
60; CHECK-NEXT:   addr %B,
61; CHECK-NEXT:   10)
62
63define void @binaryops(double* %A, double* %B) !dbg !31 {
64  %A.matrix = call <9 x double> @llvm.matrix.column.major.load(double* %A, i64 5, i1 false, i32 3, i32 3), !dbg !32
65  %R1.matrix = fadd <9 x double> %A.matrix, %A.matrix, !dbg !32
66  %R2.matrix = fmul <9 x double> %R1.matrix, %A.matrix, !dbg !32
67  call void @llvm.matrix.column.major.store(<9 x double> %R2.matrix, double* %B, i64 10, i1 false, i32 3, i32 3), !dbg !32
68  ret void
69}
70
71; CHECK-LABEL: remark: test.h:90:20: Lowered with 6 stores, 6 loads, 12 compute ops
72; CHECK-NEXT:  column.major.store.3x3.double(
73; CHECK-NEXT:   fmul(
74; CHECK-NEXT:    fadd(
75; CHECK-NEXT:     column.major.load.3x3.double(addr %A, 5)
76; CHECK-NEXT:     (reused) column.major.load.3x3.double(addr %A, 5)),
77; CHECK-NEXT:    (reused) column.major.load.3x3.double(addr %A, 5)),
78; CHECK-NEXT:   addr %B,
79; CHECK-NEXT:   10)
80; CHECK-NEXT:  remark: test.h:90:20: Lowered with 2 stores, 12 loads, 22 compute ops
81; CHECK-NEXT:  store(
82; CHECK-NEXT:   multiply.2x6.6x2.double(
83; CHECK-NEXT:    load(addr %C),
84; CHECK-NEXT:    load(addr %D)),
85; CHECK-NEXT:   addr %E)
86
87define void @multiple_expressions(double* %A, double* %B, <12 x double>* %C, <12 x double>* %D, <4 x double>* %E) !dbg !33 {
88  %A.matrix = call <9 x double> @llvm.matrix.column.major.load(double* %A, i64 5, i1 false, i32 3, i32 3), !dbg !34
89  %R1.matrix = fadd <9 x double> %A.matrix, %A.matrix, !dbg !34
90  %R2.matrix = fmul <9 x double> %R1.matrix, %A.matrix, !dbg !34
91  call void @llvm.matrix.column.major.store(<9 x double> %R2.matrix, double* %B, i64 10, i1 false, i32 3, i32 3), !dbg !34
92
93  %C.matrix = load <12 x double>, <12 x double>* %C, !dbg !34
94  %D.matrix = load <12 x double>, <12 x double>* %D, !dbg !34
95  %Mult.matrix = call <4 x double> @llvm.matrix.multiply(<12 x double> %C.matrix, <12 x double> %D.matrix, i32 2, i32 6, i32 2), !dbg !34
96  store <4 x double> %Mult.matrix, <4 x double>* %E, !dbg !34
97
98  ret void
99}
100
101; CHECK-LABEL: remark: test.h:100:20: Lowered with 6 stores, 6 loads, 12 compute ops
102; CHECK-NEXT:  column.major.store.3x3.double(
103; CHECK-NEXT:   fmul(
104; CHECK-NEXT:    fadd(
105; CHECK-NEXT:     column.major.load.3x3.double(addr %A, 5)
106; CHECK-NEXT:     (reused) column.major.load.3x3.double(addr %A, 5)),
107; CHECK-NEXT:    (reused) column.major.load.3x3.double(addr %A, 5)),
108; CHECK-NEXT:   addr %B,
109; CHECK-NEXT:   10)
110define void @stackaddresses(double* %A, double* %B) !dbg !35 {
111  %A.matrix = call <9 x double> @llvm.matrix.column.major.load(double* %A, i64 5, i1 false, i32 3, i32 3), !dbg !36
112  %R1.matrix = fadd <9 x double> %A.matrix, %A.matrix, !dbg !36
113  %R2.matrix = fmul <9 x double> %R1.matrix, %A.matrix, !dbg !36
114  call void @llvm.matrix.column.major.store(<9 x double> %R2.matrix, double* %B, i64 10, i1 false, i32 3, i32 3), !dbg !36
115  ret void
116}
117
118; CHECK-LABEL: remark: test.h:30:20: Lowered with 10 stores, 9 loads, 30 compute ops
119; CHECK-NEXT:  store(
120; CHECK-NEXT:   transpose.5x3.double(load(addr %A)),
121; CHECK-NEXT:   stack addr %s1)
122%S1 = type {<15 x double>*}
123define void @get_underlying_object(%S1* %A) !dbg !21 {
124entry:
125  %s1 = alloca <15 x double>, !dbg !22
126  %a1 = getelementptr %S1, %S1* %A, i32 0, i32 0, !dbg !22
127  %a2 = load <15 x double>*, <15 x double>** %a1, !dbg !22
128  %av = load <15 x double>, <15 x double>* %a2, !dbg !22
129
130  %s2 = bitcast <15 x double>* %s1 to i64*, !dbg !22
131  %s3 = bitcast i64* %s2 to <15 x double>*, !dbg !22
132
133  %t = call <15 x double> @llvm.matrix.transpose.v15f64.v15f64(<15 x double> %av, i32 5, i32 3), !dbg !22
134
135  store <15 x double> %t, <15 x double>* %s3, !dbg !22
136  ret void
137}
138
139declare <12 x double> @llvm.matrix.transpose.v12f64.v12f64(<12 x double>, i32, i32)
140declare <4 x double> @llvm.matrix.multiply(<12 x double>, <12 x double>, i32, i32, i32)
141declare <9 x double> @llvm.matrix.column.major.load(double*, i64, i1, i32, i32)
142declare <15 x double> @llvm.matrix.transpose.v15f64.v15f64(<15 x double>, i32, i32)
143declare void @llvm.matrix.column.major.store(<9 x double>, double*, i64, i1, i32, i32)
144
145
146!llvm.dbg.cu = !{!0}
147!llvm.module.flags = !{!3, !4}
148
149!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
150!1 = !DIFile(filename: "test.h", directory: "/test")
151!2 = !{}
152!3 = !{i32 2, !"Dwarf Version", i32 4}
153!4 = !{i32 2, !"Debug Info Version", i32 3}
154
155!6 = !DISubroutineType(types: !7)
156!7 = !{null, !8, !8, !11}
157!8 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !9)
158!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, align: 32)
159!10 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)
160!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
161!12 = !{!13}
162!13 = !DILocalVariable(name: "a", arg: 1, scope: !5, file: !1, line: 1, type: !8)
163!14 = !DILocation(line: 1, column: 27, scope: !5)
164
165!5 = distinct !DISubprogram(name: "fn1", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
166!19 = !DILocation(line: 10, column: 20, scope: !5)
167!20 = !DILocation(line: 10, column: 10, scope: !5)
168
169!21 = distinct !DISubprogram(name: "fn2", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
170!22 = !DILocation(line: 30, column: 20, scope: !21)
171
172!23 = distinct !DISubprogram(name: "fn3", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
173!24 = !DILocation(line: 40, column: 20, scope: !23)
174
175!25 = distinct !DISubprogram(name: "fn4", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
176!26 = !DILocation(line: 50, column: 20, scope: !25)
177
178!27 = distinct !DISubprogram(name: "fn5", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
179!28 = !DILocation(line: 60, column: 20, scope: !27)
180
181!29 = distinct !DISubprogram(name: "fn6", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
182!30 = !DILocation(line: 70, column: 20, scope: !29)
183
184!31 = distinct !DISubprogram(name: "fn7", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
185!32 = !DILocation(line: 80, column: 20, scope: !31)
186
187!33 = distinct !DISubprogram(name: "fn8", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
188!34 = !DILocation(line: 90, column: 20, scope: !33)
189
190!35 = distinct !DISubprogram(name: "fn9", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
191!36 = !DILocation(line: 100, column: 20, scope: !35)
192