brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.3 KiB · 618ec86 Raw
166 lines · plain
1; REQUIRES: aarch64-registered-target2 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 < %s 2>&1 | FileCheck  %s6 7; Test the propagation of matrix expressions along to inlined-at chain. The IR8; in the test roughly corresponds to the C++ code below, with the IR containing9; references to a few more functions.10 11; matrix.h12; 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.h20; 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.cpp42; 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, 0 exposed transposes51; CHECK-NEXT:  load(addr %A)52 53; CHECK-LABEL: remark: load.h:41:43: Lowered with 0 stores, 10 loads, 0 compute ops, 0 exposed transposes54; 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, 0 exposed transposes57; CHECK-NEXT: load(addr %D)58 59; CHECK-LABEL: remark: assign.h:32:43: Lowered with 0 stores, 10 loads, 0 compute ops, 0 exposed transposes60; CHECK-NEXT:  load(addr %A)61 62; CHECK-LABEL: remark: assign.h:32:43: Lowered with 0 stores, 10 loads, 0 compute ops, 0 exposed transposes63; 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, 0 exposed transposes66; 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 2 stores, 1 loads, 4 compute ops, 1 exposed transposes73; CHECK-NEXT:  store(74; CHECK-NEXT:   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, 0 exposed transposes78; 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, 0 exposed transposes83; CHECK-NEXT:  store(84; CHECK-NEXT:   scalar,85; CHECK-NEXT:   addr %C)86 87; CHECK-LABEL: remark: store.h:66:11: Lowered with 2 stores, 0 loads, 0 compute ops, 0 exposed transposes88; 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, 4 compute ops, 1 exposed transposes93; CHECK-NEXT:  transpose.2x1.float(addr %D)94 95define void @toplevel(ptr %A, ptr %B, ptr %C, ptr %D) !dbg !16 {96entry:97  %a = load <15 x double>, ptr %A, align 16, !dbg !379198  %b = call <15 x double> @llvm.matrix.column.major.load(ptr %B, i64 5, i1 false, i32 3, i32 5), !dbg !379399  %c  = fadd <15 x double> %a, %b, !dbg !100100  store <15 x double> %c, ptr %C, align 16, !dbg !102101 102  %load = load <2 x float>, ptr %D, !dbg !104103  %t1 = call <2 x float> @llvm.matrix.transpose(<2 x float> %load, i32 2, i32 1), !dbg !106104  store <2 x float> %t1, ptr %D, !dbg !108105  ret void106}107 108declare <15 x double> @llvm.matrix.column.major.load(ptr, i64, i1, i32, i32)109declare <2 x float> @llvm.matrix.transpose(<2 x float>, i32, i32)110 111!llvm.dbg.cu = !{!0}112!llvm.module.flags = !{!3, !4}113 114!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)115!1 = !DIFile(filename: "load.h", directory: "/test")116!2 = !{}117!3 = !{i32 2, !"Dwarf Version", i32 4}118!4 = !{i32 2, !"Debug Info Version", i32 3}119!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)120!17 = !DIFile(filename: "toplevel.c", directory: "/test")121!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: !2)122!18 = !DIFile(filename: "assign.h", directory: "/test")123!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: !2)124 125!20 = !DIFile(filename: "add.h", directory: "/test")126!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: !2)127 128!22 = !DIFile(filename: "store.h", directory: "/test")129!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: !2)130 131!24 = !DIFile(filename: "transpose.h", directory: "/test")132!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: !2)133 134 135!6 = !DISubroutineType(types: !7)136!7 = !{null, !8, !8, !11}137!8 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !9)138!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, align: 32)139!10 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)140!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)141!12 = !{!13}142!13 = !DILocalVariable(name: "a", arg: 1, scope: !5, file: !1, line: 1, type: !8)143!14 = !DILocation(line: 1, column: 27, scope: !5)144 145!3791 = !DILocation(line: 41, column: 43, scope: !5, inlinedAt: !3795)146!3792 = !DILocation(line: 405, column: 3, scope: !16)147!3793 = !DILocation(line: 41, column: 43, scope: !5, inlinedAt: !3796)148!3794 = !DILocation(line: 406, column: 11, scope: !16)149!3795 = !DILocation(line: 32, column: 43, scope: !19, inlinedAt: !3792)150!3796 = !DILocation(line: 32, column: 43, scope: !19, inlinedAt: !3794)151 152!100 = !DILocation(line: 66, column: 11, scope: !21, inlinedAt: !101)153!101 = !DILocation(line: 410, column: 11, scope: !16)154 155!102 = !DILocation(line: 10, column: 11, scope: !23, inlinedAt: !103)156!103 = !DILocation(line: 410, column: 0, scope: !16)157 158!104 = !DILocation(line: 41, column: 11, scope: !5, inlinedAt: !101)159!105 = !DILocation(line: 500, column: 11, scope: !16)160 161!106 = !DILocation(line: 13, column: 11, scope: !25, inlinedAt: !101)162!107 = !DILocation(line: 510, column: 11, scope: !16)163 164!108 = !DILocation(line: 66, column: 11, scope: !23, inlinedAt: !109)165!109 = !DILocation(line: 510, column: 0, scope: !16)166