180 lines · plain
1;; Test for different function processing orders affecting inlining in sample profile loader.2 3;; There is an SCC _Z5funcAi -> _Z8funcLeafi -> _Z5funcAi in the program.4;; With -use-profiled-call-graph=0, the top-down processing order of5;; that SCC is (_Z8funcLeafi, _Z5funcAi), which is determinined based on6;; the static call graph. With -use-profiled-call-graph=1, call edges7;; from profile are considered, thus the order becomes (_Z5funcAi, _Z8funcLeafi).8;; While _Z8funcLeafi is not supposed to be inlined, the outlined entry counts9;; are affected.10; RUN: opt < %s -passes=sample-profile -use-profiled-call-graph=0 -sample-profile-file=%S/Inputs/profile-topdown-order.prof -S | FileCheck %s -check-prefix=STATIC11; RUN: opt < %s -passes=sample-profile -use-profiled-call-graph=1 -sample-profile-file=%S/Inputs/profile-topdown-order.prof -S | FileCheck %s -check-prefix=DYNAMIC12 13 14; STATIC: define dso_local i32 @_Z8funcLeafi{{.*}} !prof ![[#PROF:]]15; STATIC: ![[#PROF]] = !{!"function_entry_count", i64 21}16; DYNAMIC: define dso_local i32 @_Z8funcLeafi{{.*}} !prof ![[#PROF:]]17; DYNAMIC: ![[#PROF]] = !{!"function_entry_count", i64 27}18 19@factor = dso_local global i32 3, align 4, !dbg !020@fp = dso_local global ptr null, align 821 22define dso_local i32 @_Z5funcAi(i32 %x) local_unnamed_addr #0 !dbg !40 {23entry:24 %add = add nsw i32 %x, 100000, !dbg !4425 %0 = load ptr, ptr @fp, align 826 %call = call i32 %0(i32 8), !dbg !4527 %call1 = tail call i32 @_Z8funcLeafi(i32 %add), !dbg !4628 ret i32 %call, !dbg !4629}30 31define dso_local i32 @main() local_unnamed_addr #0 !dbg !18 {32entry:33 store ptr @_Z3fibi, ptr @fp, align 8, !dbg !2534 br label %for.body, !dbg !2535 36for.cond.cleanup: ; preds = %for.body37 ret i32 %add3, !dbg !2738 39for.body: ; preds = %for.body, %entry40 %x.011 = phi i32 [ 300000, %entry ], [ %dec, %for.body ]41 %r.010 = phi i32 [ 0, %entry ], [ %add3, %for.body ]42 %call = tail call i32 @_Z5funcBi(i32 %x.011), !dbg !3243 %add = add nuw nsw i32 %x.011, 1, !dbg !3144 %call1 = tail call i32 @_Z5funcAi(i32 %add), !dbg !2845 %add2 = add i32 %call, %r.010, !dbg !3446 %add3 = add i32 %add2, %call1, !dbg !3547 %dec = add nsw i32 %x.011, -1, !dbg !3648 %cmp = icmp eq i32 %x.011, 0, !dbg !3849 br i1 %cmp, label %for.cond.cleanup, label %for.body, !dbg !2550}51 52; INLINE: define dso_local i32 @_Z8funcLeafi53; NOINLINE: define dso_local i32 @_Z8funcLeafi54; ICALL-INLINE: define dso_local i32 @_Z8funcLeafi55; ICALL-NOINLINE: define dso_local i32 @_Z8funcLeafi56define dso_local i32 @_Z8funcLeafi(i32 %x) local_unnamed_addr #1 !dbg !54 {57entry:58 %cmp = icmp sgt i32 %x, 0, !dbg !5759 br i1 %cmp, label %while.body, label %while.cond2.preheader, !dbg !5960 61while.cond2.preheader: ; preds = %entry62 %cmp313 = icmp slt i32 %x, 0, !dbg !6063 br i1 %cmp313, label %while.body4, label %if.end, !dbg !6364 65while.body: ; preds = %while.body, %entry66 %x.addr.016 = phi i32 [ %sub, %while.body ], [ %x, %entry ]67 %tmp = load volatile i32, ptr @factor, align 4, !dbg !6468 %call = tail call i32 @_Z5funcAi(i32 %tmp), !dbg !6769 %sub = sub nsw i32 %x.addr.016, %call, !dbg !6870 %cmp1 = icmp sgt i32 %sub, 0, !dbg !6971 br i1 %cmp1, label %while.body, label %if.end, !dbg !7172 73while.body4: ; preds = %while.body4, %while.cond2.preheader74 %x.addr.114 = phi i32 [ %add, %while.body4 ], [ %x, %while.cond2.preheader ]75 %tmp1 = load volatile i32, ptr @factor, align 4, !dbg !7276 %call5 = tail call i32 @_Z5funcBi(i32 %tmp1), !dbg !7477 %add = add nsw i32 %call5, %x.addr.114, !dbg !7578 %cmp3 = icmp slt i32 %add, 0, !dbg !6079 br i1 %cmp3, label %while.body4, label %if.end, !dbg !6380 81if.end: ; preds = %while.body4, %while.body, %while.cond2.preheader82 %x.addr.2 = phi i32 [ 0, %while.cond2.preheader ], [ %sub, %while.body ], [ %add, %while.body4 ]83 ret i32 %x.addr.2, !dbg !7684}85 86define dso_local i32 @_Z5funcBi(i32 %x) local_unnamed_addr #0 !dbg !47 {87entry:88 %sub = add nsw i32 %x, -100000, !dbg !5189 %call = tail call i32 @_Z8funcLeafi(i32 %sub), !dbg !5290 ret i32 %call, !dbg !5391}92 93define dso_local i32 @_Z3fibi(i32 %x) local_unnamed_addr #1 !dbg !77 {94entry:95 %sub = add nsw i32 %x, -100000, !dbg !7896 %call = tail call i32 @_Z3foo(i32 %sub), !dbg !7897 ret i32 %sub, !dbg !7898}99 100declare i32 @_Z3foo(i32)101 102attributes #0 = { nofree noinline nounwind uwtable "use-sample-profile" }103attributes #1 = { nofree nounwind uwtable "use-sample-profile" }104 105!llvm.dbg.cu = !{!2}106!llvm.module.flags = !{!14, !15, !16}107!llvm.ident = !{!17}108 109!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())110!1 = distinct !DIGlobalVariable(name: "factor", scope: !2, file: !3, line: 21, type: !13, isLocal: false, isDefinition: true)111!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !12, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)112!3 = !DIFile(filename: "merged.cpp", directory: "/local/autofdo")113!4 = !{}114!5 = !{!6, !10, !11}115!6 = !DISubprogram(name: "funcA", linkageName: "_Z5funcAi", scope: !3, file: !3, line: 6, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)116!7 = !DISubroutineType(types: !8)117!8 = !{!9, !9}118!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)119!10 = !DISubprogram(name: "funcB", linkageName: "_Z5funcBi", scope: !3, file: !3, line: 7, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)120!11 = !DISubprogram(name: "funcLeaf", linkageName: "_Z8funcLeafi", scope: !3, file: !3, line: 22, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)121!12 = !{!0}122!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !9)123!14 = !{i32 7, !"Dwarf Version", i32 4}124!15 = !{i32 2, !"Debug Info Version", i32 3}125!16 = !{i32 1, !"wchar_size", i32 4}126!17 = !{!"clang version 11.0.0"}127!18 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 11, type: !19, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21)128!19 = !DISubroutineType(types: !20)129!20 = !{!9}130!21 = !{!22, !23}131!22 = !DILocalVariable(name: "r", scope: !18, file: !3, line: 12, type: !9)132!23 = !DILocalVariable(name: "x", scope: !24, file: !3, line: 13, type: !9)133!24 = distinct !DILexicalBlock(scope: !18, file: !3, line: 13, column: 3)134!25 = !DILocation(line: 13, column: 3, scope: !26)135!26 = !DILexicalBlockFile(scope: !24, file: !3, discriminator: 2)136!27 = !DILocation(line: 17, column: 3, scope: !18)137!28 = !DILocation(line: 14, column: 10, scope: !29)138!29 = distinct !DILexicalBlock(scope: !30, file: !3, line: 13, column: 37)139!30 = distinct !DILexicalBlock(scope: !24, file: !3, line: 13, column: 3)140!31 = !DILocation(line: 14, column: 29, scope: !29)141!32 = !DILocation(line: 14, column: 21, scope: !33)142!33 = !DILexicalBlockFile(scope: !29, file: !3, discriminator: 2)143!34 = !DILocation(line: 14, column: 19, scope: !29)144!35 = !DILocation(line: 14, column: 7, scope: !29)145!36 = !DILocation(line: 13, column: 33, scope: !37)146!37 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 6)147!38 = !DILocation(line: 13, column: 26, scope: !39)148!39 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 2)149!40 = distinct !DISubprogram(name: "funcA", linkageName: "_Z5funcAi", scope: !3, file: !3, line: 26, type: !7, scopeLine: 26, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)150!44 = !DILocation(line: 26, column: 22, scope: !40)151!45 = !DILocation(line: 28, column: 11, scope: !40)152!46 = !DILocation(line: 27, column: 3, scope: !40)153!47 = distinct !DISubprogram(name: "funcB", linkageName: "_Z5funcBi", scope: !3, file: !3, line: 32, type: !7, scopeLine: 32, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)154!51 = !DILocation(line: 33, column: 22, scope: !47)155!52 = !DILocation(line: 33, column: 11, scope: !47)156!53 = !DILocation(line: 35, column: 3, scope: !47)157!54 = distinct !DISubprogram(name: "funcLeaf", linkageName: "_Z8funcLeafi", scope: !3, file: !3, line: 48, type: !7, scopeLine: 48, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)158!57 = !DILocation(line: 49, column: 9, scope: !58)159!58 = distinct !DILexicalBlock(scope: !54, file: !3, line: 49, column: 7)160!59 = !DILocation(line: 49, column: 7, scope: !54)161!60 = !DILocation(line: 58, column: 14, scope: !61)162!61 = !DILexicalBlockFile(scope: !62, file: !3, discriminator: 2)163!62 = distinct !DILexicalBlock(scope: !58, file: !3, line: 56, column: 8)164!63 = !DILocation(line: 58, column: 5, scope: !61)165!64 = !DILocation(line: 52, column: 16, scope: !65)166!65 = distinct !DILexicalBlock(scope: !66, file: !3, line: 51, column: 19)167!66 = distinct !DILexicalBlock(scope: !58, file: !3, line: 49, column: 14)168!67 = !DILocation(line: 52, column: 12, scope: !65)169!68 = !DILocation(line: 52, column: 9, scope: !65)170!69 = !DILocation(line: 51, column: 14, scope: !70)171!70 = !DILexicalBlockFile(scope: !66, file: !3, discriminator: 2)172!71 = !DILocation(line: 51, column: 5, scope: !70)173!72 = !DILocation(line: 59, column: 16, scope: !73)174!73 = distinct !DILexicalBlock(scope: !62, file: !3, line: 58, column: 19)175!74 = !DILocation(line: 59, column: 12, scope: !73)176!75 = !DILocation(line: 59, column: 9, scope: !73)177!76 = !DILocation(line: 63, column: 3, scope: !54)178!77 = distinct !DISubprogram(name: "funcB", linkageName: "_Z3fibi", scope: !3, file: !3, line: 32, type: !7, scopeLine: 32, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)179!78 = !DILocation(line: 33, column: 22, scope: !77)180