blob: 0bca099e034c06d62895c4e5a85f304e6c387fe4 [file] [log] [blame]
Florian Hahn6f07f302020-01-27 18:00:43 -08001; REQUIRES: aarch64-registered-target
Florian Hahn949294f2020-01-27 16:22:04 -08002
Florian Hahn5d0ffbe2020-01-28 09:01:00 -08003; This test needs to be target specific due to the cost estimate in the output.
4
Florian Hahn6f07f302020-01-27 18:00:43 -08005; 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 -08006
Florian Hahn62e228f2020-01-27 17:17:17 -08007; CHECK-LABEL: remark: test.h:40:20: Lowered with 6 stores, 6 loads, 24 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -08008; 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
18declare <12 x double> @llvm.matrix.transpose.v12f64.v12f64(<12 x double>, i32, i32)
19
20
Florian Hahn62e228f2020-01-27 17:17:17 -080021; CHECK-LABEL: remark: test.h:50:20: Lowered with 2 stores, 12 loads, 22 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080022; CHECK-NEXT: store(
23; CHECK-NEXT: multiply.2x6.6x2.double(
24; CHECK-NEXT: load(addr %A),
25; CHECK-NEXT: load(addr %B)),
26; CHECK-NEXT: addr %C)
27define void @multiply(<12 x double>* %A, <12 x double>* %B, <4 x double>* %C) !dbg !25 {
28 %A.matrix = load <12 x double>, <12 x double>* %A, !dbg !26
29 %B.matrix = load <12 x double>, <12 x double>* %B, !dbg !26
30 %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
31 store <4 x double> %t, <4 x double>* %C, !dbg !26
32 ret void
33}
34
35declare <4 x double> @llvm.matrix.multiply(<12 x double>, <12 x double>, i32, i32, i32)
36
Florian Hahn62e228f2020-01-27 17:17:17 -080037; CHECK-LABEL: remark: test.h:60:20: Lowered with 6 stores, 6 loads, 0 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080038; CHECK-NEXT: store(
39; CHECK-NEXT: columnwise.load.3x3.double(addr %A, 5),
40; CHECK-NEXT: addr %B)
41define void @columnwise.load(<9 x double>* %A, <9 x double>* %B) !dbg !27 {
42 %A.matrix = call <9 x double> @llvm.matrix.columnwise.load(<9 x double>* %A, i32 5, i32 3, i32 3), !dbg !28
43 store <9 x double> %A.matrix, <9 x double>* %B, !dbg !28
44 ret void
45}
46
47declare <9 x double> @llvm.matrix.columnwise.load(<9 x double>*, i32, i32, i32)
48
Florian Hahn62e228f2020-01-27 17:17:17 -080049; CHECK-LABEL: remark: test.h:70:20: Lowered with 6 stores, 6 loads, 0 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080050; CHECK-NEXT: columnwise.store.3x3.double(
51; CHECK-NEXT: columnwise.load.3x3.double(addr %A, 5),
52; CHECK-NEXT: addr %B,
53; CHECK-NEXT: 10)
54define void @columnwise.store(<9 x double>* %A, <9 x double>* %B) !dbg !29 {
55 %A.matrix = call <9 x double> @llvm.matrix.columnwise.load(<9 x double>* %A, i32 5, i32 3, i32 3), !dbg !30
56 call void @llvm.matrix.columnwise.store(<9 x double> %A.matrix, <9 x double>* %B, i32 10, i32 3, i32 3), !dbg !30
57 ret void
58}
59
60declare void @llvm.matrix.columnwise.store(<9 x double>, <9 x double>*, i32, i32, i32)
61
Florian Hahn62e228f2020-01-27 17:17:17 -080062; CHECK-LABEL: remark: test.h:80:20: Lowered with 6 stores, 6 loads, 12 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080063; CHECK-NEXT: columnwise.store.3x3.double(
64; CHECK-NEXT: fmul(
65; CHECK-NEXT: fadd(
66; CHECK-NEXT: columnwise.load.3x3.double(addr %A, 5)
67; CHECK-NEXT: (reused) columnwise.load.3x3.double(addr %A, 5)),
68; CHECK-NEXT: (reused) columnwise.load.3x3.double(addr %A, 5)),
69; CHECK-NEXT: addr %B,
70; CHECK-NEXT: 10)
71
72define void @binaryops(<9 x double>* %A, <9 x double>* %B) !dbg !31 {
73 %A.matrix = call <9 x double> @llvm.matrix.columnwise.load(<9 x double>* %A, i32 5, i32 3, i32 3), !dbg !32
74 %R1.matrix = fadd <9 x double> %A.matrix, %A.matrix
75 %R2.matrix = fmul <9 x double> %R1.matrix, %A.matrix
76 call void @llvm.matrix.columnwise.store(<9 x double> %R2.matrix, <9 x double>* %B, i32 10, i32 3, i32 3), !dbg !32
77 ret void
78}
79
Florian Hahn62e228f2020-01-27 17:17:17 -080080; CHECK-LABEL: remark: test.h:90:20: Lowered with 6 stores, 6 loads, 12 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080081; CHECK-NEXT: columnwise.store.3x3.double(
82; CHECK-NEXT: fmul(
83; CHECK-NEXT: fadd(
84; CHECK-NEXT: columnwise.load.3x3.double(addr %A, 5)
85; CHECK-NEXT: (reused) columnwise.load.3x3.double(addr %A, 5)),
86; CHECK-NEXT: (reused) columnwise.load.3x3.double(addr %A, 5)),
87; CHECK-NEXT: addr %B,
88; CHECK-NEXT: 10)
Florian Hahn62e228f2020-01-27 17:17:17 -080089; CHECK-NEXT: remark: test.h:90:20: Lowered with 2 stores, 12 loads, 22 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080090; CHECK-NEXT: store(
91; CHECK-NEXT: multiply.2x6.6x2.double(
92; CHECK-NEXT: load(addr %C),
93; CHECK-NEXT: load(addr %D)),
94; CHECK-NEXT: addr %E)
95
96define 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 {
97 %A.matrix = call <9 x double> @llvm.matrix.columnwise.load(<9 x double>* %A, i32 5, i32 3, i32 3), !dbg !34
98 %R1.matrix = fadd <9 x double> %A.matrix, %A.matrix
99 %R2.matrix = fmul <9 x double> %R1.matrix, %A.matrix
100 call void @llvm.matrix.columnwise.store(<9 x double> %R2.matrix, <9 x double>* %B, i32 10, i32 3, i32 3), !dbg !34
101
102 %C.matrix = load <12 x double>, <12 x double>* %C, !dbg !34
103 %D.matrix = load <12 x double>, <12 x double>* %D, !dbg !34
104 %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
105 store <4 x double> %Mult.matrix, <4 x double>* %E, !dbg !34
106
107 ret void
108}
109
Florian Hahn62e228f2020-01-27 17:17:17 -0800110; CHECK-LABEL: remark: test.h:100:20: Lowered with 6 stores, 6 loads, 12 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -0800111; CHECK-NEXT: columnwise.store.3x3.double(
112; CHECK-NEXT: fmul(
113; CHECK-NEXT: fadd(
114; CHECK-NEXT: columnwise.load.3x3.double(addr %A, 5)
115; CHECK-NEXT: (reused) columnwise.load.3x3.double(addr %A, 5)),
116; CHECK-NEXT: (reused) columnwise.load.3x3.double(addr %A, 5)),
117; CHECK-NEXT: stack addr %B,
118; CHECK-NEXT: 10)
119define void @stackaddresses(<9 x double>* %A) !dbg !35 {
120 %B = alloca <9 x double>
121 %A.matrix = call <9 x double> @llvm.matrix.columnwise.load(<9 x double>* %A, i32 5, i32 3, i32 3), !dbg !36
122 %R1.matrix = fadd <9 x double> %A.matrix, %A.matrix
123 %R2.matrix = fmul <9 x double> %R1.matrix, %A.matrix
124 call void @llvm.matrix.columnwise.store(<9 x double> %R2.matrix, <9 x double>* %B, i32 10, i32 3, i32 3), !dbg !36
125 ret void
126}
127
Florian Hahn62e228f2020-01-27 17:17:17 -0800128; CHECK-LABEL: remark: test.h:30:20: Lowered with 10 stores, 9 loads, 30 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -0800129; CHECK-NEXT: store(
130; CHECK-NEXT: transpose.5x3.double(load(addr %A)),
131; CHECK-NEXT: stack addr %s1)
132%S1 = type {<15 x double>*}
133define void @get_underlying_object(%S1* %A) !dbg !21 {
134entry:
135 %s1 = alloca <15 x double>, !dbg !22
136 %a1 = getelementptr %S1, %S1* %A, i32 0, i32 0, !dbg !22
137 %a2 = load <15 x double>*, <15 x double>** %a1, !dbg !22
138 %av = load <15 x double>, <15 x double>* %a2, !dbg !22
139
140 %s2 = bitcast <15 x double>* %s1 to i64*, !dbg !22
141 %s3 = bitcast i64* %s2 to <15 x double>*, !dbg !22
142
143 %t = call <15 x double> @llvm.matrix.transpose.v15f64.v15f64(<15 x double> %av, i32 5, i32 3)
144
145 store <15 x double> %t, <15 x double>* %s3, !dbg !22
146 ret void
147}
148
149declare <15 x double> @llvm.matrix.transpose.v15f64.v15f64(<15 x double>, i32, i32)
150
151!llvm.dbg.cu = !{!0}
152!llvm.module.flags = !{!3, !4}
153
154!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
155!1 = !DIFile(filename: "test.h", directory: "/test")
156!2 = !{}
157!3 = !{i32 2, !"Dwarf Version", i32 4}
158!4 = !{i32 2, !"Debug Info Version", i32 3}
159
160!6 = !DISubroutineType(types: !7)
161!7 = !{null, !8, !8, !11}
162!8 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !9)
163!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, align: 32)
164!10 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)
165!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
166!12 = !{!13}
167!13 = !DILocalVariable(name: "a", arg: 1, scope: !5, file: !1, line: 1, type: !8)
168!14 = !DILocation(line: 1, column: 27, scope: !5)
169
170!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)
171!19 = !DILocation(line: 10, column: 20, scope: !5)
172!20 = !DILocation(line: 10, column: 10, scope: !5)
173
174!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)
175!22 = !DILocation(line: 30, column: 20, scope: !21)
176
177!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)
178!24 = !DILocation(line: 40, column: 20, scope: !23)
179
180!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)
181!26 = !DILocation(line: 50, column: 20, scope: !25)
182
183!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)
184!28 = !DILocation(line: 60, column: 20, scope: !27)
185
186!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)
187!30 = !DILocation(line: 70, column: 20, scope: !29)
188
189!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)
190!32 = !DILocation(line: 80, column: 20, scope: !31)
191
192!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)
193!34 = !DILocation(line: 90, column: 20, scope: !33)
194
195!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)
196!36 = !DILocation(line: 100, column: 20, scope: !35)