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 -lower-matrix-intrinsics -pass-remarks=lower-matrix-intrinsics -mtriple=arm64-apple-iphoneos -S < %s 2>&1 | FileCheck %s 6 7; Test the propagation of matrix expressions along to inlined-at chain. The IR 8; in the test roughly corresponds to the C++ code below, with the IR containing 9; references to a few more functions. 10 11; matrix.h 12; template <typename Ty, unsigned R, unsigned C> 13; struct Matrix { 14; using matrix_t = Ty __attribute__((matrix_type(R, C))); 15; 16; matrix_t value; 17; }; 18; 19; ; add.h 20; template <typename Ty, unsigned R, unsigned C> 21; Matrix<Ty, R, C> add(Matrix<Ty, R, C> M1, Matrix<Ty, R, C> M2) { 22; Matrix<Ty, R, C> Result; 23; Result.value = __builtin_matrix_add(M1.value, M2.value); 24; return Result; 25; } 26; 27; load.h: 28; template <typename Ty, unsigned R, unsigned C> 29; Matrix<Ty, R, C> load(Ty *Ptr) { 30; Matrix<Ty, R, C> Result; 31; Result.value = *reinterpret_cast <typename Matrix<Ty, R, C>::matrix_t *>(Ptr); 32; return Result; 33; } 34; 35; store.h: 36; template <typename Ty, unsigned R, unsigned C> 37; void store(Matrix<Ty, R, C> M1, Ty *Ptr) { 38; *reinterpret_cast<typename decltype(M1)::matrix_t *>(Ptr) = M1.value; 39; } 40; 41; toplevel.cpp 42; void test(double *A, double *B, double *C) { 43; store(add(load<double, 3, 5>(A), load<double, 3, 5>(B)), C); 44; } 45; 46 47target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 48target triple = "aarch64-apple-ios" 49 50; CHECK-LABEL: remark: load.h:41:43: Lowered with 0 stores, 10 loads, 0 compute ops 51; CHECK-NEXT: load(addr %A) 52 53; CHECK-LABEL: remark: load.h:41:43: Lowered with 0 stores, 10 loads, 0 compute ops 54; CHECK-NEXT: column.major.load.3x5.double(addr %B, 5) 55 56; CHECK-LABEL: remark: load.h:41:11: Lowered with 0 stores, 1 loads, 0 compute ops 57; CHECK-NEXT: load(addr %D) 58 59; CHECK-LABEL: remark: assign.h:32:43: Lowered with 0 stores, 10 loads, 0 compute ops 60; CHECK-NEXT: load(addr %A) 61 62; CHECK-LABEL: remark: assign.h:32:43: Lowered with 0 stores, 10 loads, 0 compute ops 63; CHECK-NEXT: column.major.load.3x5.double(addr %B, 5) 64 65; CHECK-LABEL: remark: toplevel.c:410:0: Lowered with 10 stores, 20 loads, 10 compute ops 66; CHECK-NEXT: store( 67; CHECK-NEXT: fadd( 68; CHECK-NEXT: load(addr %A), 69; CHECK-NEXT: column.major.load.3x5.double(addr %B, 5)), 70; CHECK-NEXT: addr %C) 71 72; CHECK-LABEL: remark: toplevel.c:510:0: Lowered with 1 stores, 1 loads, 8 compute ops 73; CHECK-NEXT: store( 74; CHECK-NEXT: transpose.1x2.float(transpose.2x1.float(load(addr %D))), 75; CHECK-NEXT: addr %D) 76 77; CHECK-LABEL: remark: add.h:66:11: Lowered with 0 stores, 0 loads, 10 compute ops 78; CHECK-NEXT: fadd( 79; CHECK-NEXT: addr %A, 80; CHECK-NEXT: scalar) 81 82; CHECK-LABEL: remark: store.h:10:11: Lowered with 10 stores, 0 loads, 0 compute ops 83; CHECK-NEXT: store( 84; CHECK-NEXT: scalar, 85; CHECK-NEXT: addr %C) 86 87; CHECK-LABEL: remark: store.h:66:11: Lowered with 1 stores, 0 loads, 0 compute ops 88; CHECK-NEXT: store( 89; CHECK-NEXT: scalar, 90; CHECK-NEXT: addr %D) 91 92; CHECK-LABEL: remark: transpose.h:13:11: Lowered with 0 stores, 0 loads, 8 compute ops 93; CHECK-NEXT: transpose.1x2.float(transpose.2x1.float(addr %D)) 94 95define void @toplevel(<15 x double>* %A, double* %B, <15 x double>* %C, <2 x float>* %D) !dbg !16 { 96entry: 97 %a = load <15 x double>, <15 x double> *%A, align 16, !dbg !3791 98 %b = call <15 x double> @llvm.matrix.column.major.load(double* %B, i64 5, i1 false, i32 3, i32 5), !dbg !3793 99 %c = fadd <15 x double> %a, %b, !dbg !100 100 store <15 x double> %c, <15 x double> *%C, align 16, !dbg !102 101 102 %load = load <2 x float>, <2 x float>* %D, !dbg !104 103 %t1 = call <2 x float> @llvm.matrix.transpose(<2 x float> %load, i32 2, i32 1), !dbg !106 104 %t2 = call <2 x float> @llvm.matrix.transpose(<2 x float> %t1, i32 1, i32 2), !dbg !106 105 store <2 x float> %t2, <2 x float>* %D, !dbg !108 106 ret void 107} 108 109declare <15 x double> @llvm.matrix.column.major.load(double*, i64, i1, i32, i32) 110declare <2 x float> @llvm.matrix.transpose(<2 x float>, i32, i32) 111 112!llvm.dbg.cu = !{!0} 113!llvm.module.flags = !{!3, !4} 114 115!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 116!1 = !DIFile(filename: "load.h", directory: "/test") 117!2 = !{} 118!3 = !{i32 2, !"Dwarf Version", i32 4} 119!4 = !{i32 2, !"Debug Info Version", i32 3} 120!5 = distinct !DISubprogram(name: "load_fn", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) 121!17 = !DIFile(filename: "toplevel.c", directory: "/test") 122!16 = distinct !DISubprogram(name: "toplevel", scope: !1, file: !17, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) 123!18 = !DIFile(filename: "assign.h", directory: "/test") 124!19 = distinct !DISubprogram(name: "assign", scope: !1, file: !18, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) 125 126!20 = !DIFile(filename: "add.h", directory: "/test") 127!21 = distinct !DISubprogram(name: "add_fn", scope: !1, file: !20, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) 128 129!22 = !DIFile(filename: "store.h", directory: "/test") 130!23 = distinct !DISubprogram(name: "store_fn", scope: !1, file: !22, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) 131 132!24 = !DIFile(filename: "transpose.h", directory: "/test") 133!25 = distinct !DISubprogram(name: "transpose", scope: !1, file: !24, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) 134 135 136!6 = !DISubroutineType(types: !7) 137!7 = !{null, !8, !8, !11} 138!8 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !9) 139!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, align: 32) 140!10 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float) 141!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 142!12 = !{!13} 143!13 = !DILocalVariable(name: "a", arg: 1, scope: !5, file: !1, line: 1, type: !8) 144!14 = !DILocation(line: 1, column: 27, scope: !5) 145 146!3791 = !DILocation(line: 41, column: 43, scope: !5, inlinedAt: !3795) 147!3792 = !DILocation(line: 405, column: 3, scope: !16) 148!3793 = !DILocation(line: 41, column: 43, scope: !5, inlinedAt: !3796) 149!3794 = !DILocation(line: 406, column: 11, scope: !16) 150!3795 = !DILocation(line: 32, column: 43, scope: !19, inlinedAt: !3792) 151!3796 = !DILocation(line: 32, column: 43, scope: !19, inlinedAt: !3794) 152 153!100 = !DILocation(line: 66, column: 11, scope: !21, inlinedAt: !101) 154!101 = !DILocation(line: 410, column: 11, scope: !16) 155 156!102 = !DILocation(line: 10, column: 11, scope: !23, inlinedAt: !103) 157!103 = !DILocation(line: 410, column: 0, scope: !16) 158 159!104 = !DILocation(line: 41, column: 11, scope: !5, inlinedAt: !101) 160!105 = !DILocation(line: 500, column: 11, scope: !16) 161 162!106 = !DILocation(line: 13, column: 11, scope: !25, inlinedAt: !101) 163!107 = !DILocation(line: 510, column: 11, scope: !16) 164 165!108 = !DILocation(line: 66, column: 11, scope: !23, inlinedAt: !109) 166!109 = !DILocation(line: 510, column: 0, scope: !16) 167