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