blob: ae5ab68c4efb102f6d197bc8cfe49717fc7febc2 [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
Florian Hahn62e228f2020-01-27 17:17:17 -080018; CHECK-LABEL: remark: test.h:50:20: Lowered with 2 stores, 12 loads, 22 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080019; 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
Florian Hahn62e228f2020-01-27 17:17:17 -080032; CHECK-LABEL: remark: test.h:60:20: Lowered with 6 stores, 6 loads, 0 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080033; CHECK-NEXT: store(
Florian Hahn6d18c202020-06-18 09:30:41 +010034; CHECK-NEXT: column.major.load.3x3.double(addr %A, 5),
Florian Hahn949294f2020-01-27 16:22:04 -080035; CHECK-NEXT: addr %B)
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +010036define 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
Florian Hahn949294f2020-01-27 16:22:04 -080038 store <9 x double> %A.matrix, <9 x double>* %B, !dbg !28
39 ret void
40}
41
Florian Hahn62e228f2020-01-27 17:17:17 -080042; CHECK-LABEL: remark: test.h:70:20: Lowered with 6 stores, 6 loads, 0 compute ops
Florian Hahn6d18c202020-06-18 09:30:41 +010043; CHECK-NEXT: column.major.store.3x3.double(
44; CHECK-NEXT: column.major.load.3x3.double(addr %A, 5),
Florian Hahn949294f2020-01-27 16:22:04 -080045; CHECK-NEXT: addr %B,
46; CHECK-NEXT: 10)
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +010047define 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
Florian Hahn949294f2020-01-27 16:22:04 -080050 ret void
51}
52
Florian Hahn62e228f2020-01-27 17:17:17 -080053; CHECK-LABEL: remark: test.h:80:20: Lowered with 6 stores, 6 loads, 12 compute ops
Florian Hahn6d18c202020-06-18 09:30:41 +010054; CHECK-NEXT: column.major.store.3x3.double(
Florian Hahn949294f2020-01-27 16:22:04 -080055; CHECK-NEXT: fmul(
56; CHECK-NEXT: fadd(
Florian Hahn6d18c202020-06-18 09:30:41 +010057; 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)),
Florian Hahn949294f2020-01-27 16:22:04 -080060; CHECK-NEXT: addr %B,
61; CHECK-NEXT: 10)
62
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +010063define 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
Florian Hahnbc6c8c42020-03-11 17:01:47 +000065 %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
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +010067 call void @llvm.matrix.column.major.store(<9 x double> %R2.matrix, double* %B, i64 10, i1 false, i32 3, i32 3), !dbg !32
Florian Hahn949294f2020-01-27 16:22:04 -080068 ret void
69}
70
Florian Hahn62e228f2020-01-27 17:17:17 -080071; CHECK-LABEL: remark: test.h:90:20: Lowered with 6 stores, 6 loads, 12 compute ops
Florian Hahn6d18c202020-06-18 09:30:41 +010072; CHECK-NEXT: column.major.store.3x3.double(
Florian Hahn949294f2020-01-27 16:22:04 -080073; CHECK-NEXT: fmul(
74; CHECK-NEXT: fadd(
Florian Hahn6d18c202020-06-18 09:30:41 +010075; 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)),
Florian Hahn949294f2020-01-27 16:22:04 -080078; CHECK-NEXT: addr %B,
79; CHECK-NEXT: 10)
Florian Hahn62e228f2020-01-27 17:17:17 -080080; CHECK-NEXT: remark: test.h:90:20: Lowered with 2 stores, 12 loads, 22 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -080081; 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
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +010087define 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
Florian Hahnbc6c8c42020-03-11 17:01:47 +000089 %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
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +010091 call void @llvm.matrix.column.major.store(<9 x double> %R2.matrix, double* %B, i64 10, i1 false, i32 3, i32 3), !dbg !34
Florian Hahn949294f2020-01-27 16:22:04 -080092
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
Florian Hahn62e228f2020-01-27 17:17:17 -0800101; CHECK-LABEL: remark: test.h:100:20: Lowered with 6 stores, 6 loads, 12 compute ops
Florian Hahn6d18c202020-06-18 09:30:41 +0100102; CHECK-NEXT: column.major.store.3x3.double(
Florian Hahn949294f2020-01-27 16:22:04 -0800103; CHECK-NEXT: fmul(
104; CHECK-NEXT: fadd(
Florian Hahn6d18c202020-06-18 09:30:41 +0100105; 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)),
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +0100108; CHECK-NEXT: addr %B,
Florian Hahn949294f2020-01-27 16:22:04 -0800109; CHECK-NEXT: 10)
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +0100110define 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
Florian Hahnbc6c8c42020-03-11 17:01:47 +0000112 %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
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +0100114 call void @llvm.matrix.column.major.store(<9 x double> %R2.matrix, double* %B, i64 10, i1 false, i32 3, i32 3), !dbg !36
Florian Hahn949294f2020-01-27 16:22:04 -0800115 ret void
116}
117
Florian Hahn62e228f2020-01-27 17:17:17 -0800118; CHECK-LABEL: remark: test.h:30:20: Lowered with 10 stores, 9 loads, 30 compute ops
Florian Hahn949294f2020-01-27 16:22:04 -0800119; 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
Florian Hahnbc6c8c42020-03-11 17:01:47 +0000133 %t = call <15 x double> @llvm.matrix.transpose.v15f64.v15f64(<15 x double> %av, i32 5, i32 3), !dbg !22
Florian Hahn949294f2020-01-27 16:22:04 -0800134
135 store <15 x double> %t, <15 x double>* %s3, !dbg !22
136 ret void
137}
138
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +0100139declare <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)
Florian Hahn949294f2020-01-27 16:22:04 -0800142declare <15 x double> @llvm.matrix.transpose.v15f64.v15f64(<15 x double>, i32, i32)
Sjoerd Meijer2b3c5052020-07-14 11:01:05 +0100143declare void @llvm.matrix.column.major.store(<9 x double>, double*, i64, i1, i32, i32)
144
Florian Hahn949294f2020-01-27 16:22:04 -0800145
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)