167 lines · plain
1; REQUIRES: asserts2; Test that the new FDO inliner using prioty queue will not visit same call site again and again.3; Use debug prints as repeated call site evaluation is not visible from final inline decision.4 5; Note that we need new pass manager to enable top-down processing for sample profile loader6; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profile-context-tracker.prof -sample-profile-inline-size -sample-profile-prioritized-inline=0 -debug-only=sample-context-tracker -o /dev/null 2>&1 | FileCheck %s --check-prefix=OLD-INLINE7; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profile-context-tracker.prof -sample-profile-inline-size -sample-profile-prioritized-inline=1 -debug-only=sample-context-tracker -o /dev/null 2>&1 | FileCheck %s --check-prefix=NEW-INLINE8 9; Old inliner will evaluate the same call site three times10; OLD-INLINE: Getting callee context for instr: %call = tail call i32 @_Z5funcBi11; OLD-INLINE-NEXT: Callee context found: main:3.1 @ _Z5funcBi12; OLD-INLINE: Getting callee context for instr: %call = tail call i32 @_Z5funcBi13; OLD-INLINE-NEXT: Callee context found: main:3.1 @ _Z5funcBi14; OLD-INLINE: Getting callee context for instr: %call = tail call i32 @_Z5funcBi15; OLD-INLINE-NEXT: Callee context found: main:3.1 @ _Z5funcBi16 17; New inliner only evaluate the same call site once18; NEW-INLINE: Getting callee context for instr: %call = tail call i32 @_Z5funcBi19; NEW-INLINE-NEXT: Callee context found: main:3.1 @ _Z5funcBi20; NEW-INLINE-NOT: Getting callee context for instr: %call = tail call i32 @_Z5funcBi21; NEW-INLINE-NOT: Callee context found: main:3.1 @ _Z5funcBi22 23@factor = dso_local global i32 3, align 4, !dbg !024 25define dso_local i32 @main() local_unnamed_addr #0 !dbg !18 {26entry:27 br label %for.body, !dbg !2528 29for.cond.cleanup: ; preds = %for.body30 ret i32 %add3, !dbg !2731 32for.body: ; preds = %for.body, %entry33 %x.011 = phi i32 [ 300000, %entry ], [ %dec, %for.body ]34 %r.010 = phi i32 [ 0, %entry ], [ %add3, %for.body ]35 %call = tail call i32 @_Z5funcBi(i32 %x.011), !dbg !3236 %add = add nuw nsw i32 %x.011, 1, !dbg !3137 %call1 = tail call i32 @_Z5funcAi(i32 %add), !dbg !2838 %add2 = add i32 %call, %r.010, !dbg !3439 %add3 = add i32 %add2, %call1, !dbg !3540 %dec = add nsw i32 %x.011, -1, !dbg !3641 %cmp = icmp eq i32 %x.011, 0, !dbg !3842 br i1 %cmp, label %for.cond.cleanup, label %for.body, !dbg !2543}44 45define dso_local i32 @_Z5funcAi(i32 %x) local_unnamed_addr #1 !dbg !40 {46entry:47 %add = add nsw i32 %x, 100000, !dbg !4448 %call = tail call i32 @_Z8funcLeafi(i32 %add), !dbg !4549 ret i32 %call, !dbg !4650}51 52define dso_local i32 @_Z8funcLeafi(i32 %x) local_unnamed_addr #1 !dbg !54 {53entry:54 %cmp = icmp sgt i32 %x, 0, !dbg !5755 br i1 %cmp, label %while.body, label %while.cond2.preheader, !dbg !5956 57while.cond2.preheader: ; preds = %entry58 %cmp313 = icmp slt i32 %x, 0, !dbg !6059 br i1 %cmp313, label %while.body4, label %if.end, !dbg !6360 61while.body: ; preds = %while.body, %entry62 %x.addr.016 = phi i32 [ %sub, %while.body ], [ %x, %entry ]63 %tmp = load volatile i32, ptr @factor, align 4, !dbg !6464 %call = tail call i32 @_Z3fibi(i32 %tmp), !dbg !6765 %sub = sub nsw i32 %x.addr.016, %call, !dbg !6866 %cmp1 = icmp sgt i32 %sub, 0, !dbg !6967 br i1 %cmp1, label %while.body, label %if.end, !dbg !7168 69while.body4: ; preds = %while.body4, %while.cond2.preheader70 %x.addr.114 = phi i32 [ %add, %while.body4 ], [ %x, %while.cond2.preheader ]71 %tmp1 = load volatile i32, ptr @factor, align 4, !dbg !7272 %call5 = tail call i32 @_Z3fibi(i32 %tmp1), !dbg !7473 %add = add nsw i32 %call5, %x.addr.114, !dbg !7574 %cmp3 = icmp slt i32 %add, 0, !dbg !6075 br i1 %cmp3, label %while.body4, label %if.end, !dbg !6376 77if.end: ; preds = %while.body4, %while.body, %while.cond2.preheader78 %x.addr.2 = phi i32 [ 0, %while.cond2.preheader ], [ %sub, %while.body ], [ %add, %while.body4 ]79 ret i32 %x.addr.2, !dbg !7680}81 82define dso_local i32 @_Z5funcBi(i32 %x) local_unnamed_addr #0 !dbg !47 {83entry:84 %sub = add nsw i32 %x, -100000, !dbg !5185 %call = tail call i32 @_Z8funcLeafi(i32 %sub), !dbg !5286 ret i32 %call, !dbg !5387}88 89declare i32 @_Z3fibi(i32)90 91attributes #0 = { nofree noinline norecurse nounwind uwtable "use-sample-profile" }92attributes #1 = { nofree norecurse nounwind uwtable "use-sample-profile" }93 94!llvm.dbg.cu = !{!2}95!llvm.module.flags = !{!14, !15, !16}96!llvm.ident = !{!17}97 98!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())99!1 = distinct !DIGlobalVariable(name: "factor", scope: !2, file: !3, line: 21, type: !13, isLocal: false, isDefinition: true)100!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)101!3 = !DIFile(filename: "merged.cpp", directory: "/local/autofdo")102!4 = !{}103!5 = !{!6, !10, !11}104!6 = !DISubprogram(name: "funcA", linkageName: "_Z5funcAi", scope: !3, file: !3, line: 6, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)105!7 = !DISubroutineType(types: !8)106!8 = !{!9, !9}107!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)108!10 = !DISubprogram(name: "funcB", linkageName: "_Z5funcBi", scope: !3, file: !3, line: 7, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)109!11 = !DISubprogram(name: "funcLeaf", linkageName: "_Z8funcLeafi", scope: !3, file: !3, line: 22, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)110!12 = !{!0}111!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !9)112!14 = !{i32 7, !"Dwarf Version", i32 4}113!15 = !{i32 2, !"Debug Info Version", i32 3}114!16 = !{i32 1, !"wchar_size", i32 4}115!17 = !{!"clang version 11.0.0"}116!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)117!19 = !DISubroutineType(types: !20)118!20 = !{!9}119!21 = !{!22, !23}120!22 = !DILocalVariable(name: "r", scope: !18, file: !3, line: 12, type: !9)121!23 = !DILocalVariable(name: "x", scope: !24, file: !3, line: 13, type: !9)122!24 = distinct !DILexicalBlock(scope: !18, file: !3, line: 13, column: 3)123!25 = !DILocation(line: 13, column: 3, scope: !26)124!26 = !DILexicalBlockFile(scope: !24, file: !3, discriminator: 2)125!27 = !DILocation(line: 17, column: 3, scope: !18)126!28 = !DILocation(line: 14, column: 10, scope: !29)127!29 = distinct !DILexicalBlock(scope: !30, file: !3, line: 13, column: 37)128!30 = distinct !DILexicalBlock(scope: !24, file: !3, line: 13, column: 3)129!31 = !DILocation(line: 14, column: 29, scope: !29)130!32 = !DILocation(line: 14, column: 21, scope: !33)131!33 = !DILexicalBlockFile(scope: !29, file: !3, discriminator: 2)132!34 = !DILocation(line: 14, column: 19, scope: !29)133!35 = !DILocation(line: 14, column: 7, scope: !29)134!36 = !DILocation(line: 13, column: 33, scope: !37)135!37 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 6)136!38 = !DILocation(line: 13, column: 26, scope: !39)137!39 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 2)138!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)139!44 = !DILocation(line: 27, column: 22, scope: !40)140!45 = !DILocation(line: 27, column: 11, scope: !40)141!46 = !DILocation(line: 29, column: 3, scope: !40)142!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)143!51 = !DILocation(line: 33, column: 22, scope: !47)144!52 = !DILocation(line: 33, column: 11, scope: !47)145!53 = !DILocation(line: 35, column: 3, scope: !47)146!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)147!57 = !DILocation(line: 49, column: 9, scope: !58)148!58 = distinct !DILexicalBlock(scope: !54, file: !3, line: 49, column: 7)149!59 = !DILocation(line: 49, column: 7, scope: !54)150!60 = !DILocation(line: 58, column: 14, scope: !61)151!61 = !DILexicalBlockFile(scope: !62, file: !3, discriminator: 2)152!62 = distinct !DILexicalBlock(scope: !58, file: !3, line: 56, column: 8)153!63 = !DILocation(line: 58, column: 5, scope: !61)154!64 = !DILocation(line: 52, column: 16, scope: !65)155!65 = distinct !DILexicalBlock(scope: !66, file: !3, line: 51, column: 19)156!66 = distinct !DILexicalBlock(scope: !58, file: !3, line: 49, column: 14)157!67 = !DILocation(line: 52, column: 12, scope: !65)158!68 = !DILocation(line: 52, column: 9, scope: !65)159!69 = !DILocation(line: 51, column: 14, scope: !70)160!70 = !DILexicalBlockFile(scope: !66, file: !3, discriminator: 2)161!71 = !DILocation(line: 51, column: 5, scope: !70)162!72 = !DILocation(line: 59, column: 16, scope: !73)163!73 = distinct !DILexicalBlock(scope: !62, file: !3, line: 58, column: 19)164!74 = !DILocation(line: 59, column: 12, scope: !73)165!75 = !DILocation(line: 59, column: 9, scope: !73)166!76 = !DILocation(line: 63, column: 3, scope: !54)167