1de40f6d6SHongtao Yu;; Test for different function processing orders affecting inlining in sample profile loader. 2de40f6d6SHongtao Yu 3de40f6d6SHongtao Yu;; There is an SCC _Z5funcAi -> _Z8funcLeafi -> _Z5funcAi in the program. 43e3fc431SHongtao Yu;; With -use-profiled-call-graph=0, the top-down processing order of 5de40f6d6SHongtao Yu;; that SCC is (_Z8funcLeafi, _Z5funcAi), which is determinined based on 63e3fc431SHongtao Yu;; the static call graph. With -use-profiled-call-graph=1, call edges 7de40f6d6SHongtao Yu;; from profile are considered, thus the order becomes (_Z5funcAi, _Z8funcLeafi) 8de40f6d6SHongtao Yu;; which leads to _Z8funcLeafi inlined into _Z5funcAi. 93e3fc431SHongtao Yu; RUN: opt < %s -passes=sample-profile -use-profiled-call-graph=1 -sample-profile-file=%S/Inputs/profile-context-order.prof -S | FileCheck %s -check-prefix=INLINE 103e3fc431SHongtao Yu; RUN: opt < %s -passes=sample-profile -use-profiled-call-graph=0 -sample-profile-file=%S/Inputs/profile-context-order.prof -S | FileCheck %s -check-prefix=NOINLINE 11de40f6d6SHongtao Yu 12de40f6d6SHongtao Yu;; There is an indirect call _Z5funcAi -> _Z3fibi in the program. 133e3fc431SHongtao Yu;; With -use-profiled-call-graph=0, the processing order computed 14de40f6d6SHongtao Yu;; based on the static call graph is (_Z3fibi, _Z5funcAi). With 153e3fc431SHongtao Yu;; -use-profiled-call-graph=1, the indirect call edge from profile is 16de40f6d6SHongtao Yu;; considered, thus the order becomes (_Z5funcAi, _Z3fibi) which leads to 17de40f6d6SHongtao Yu;; _Z3fibi inlined into _Z5funcAi. 183e3fc431SHongtao Yu; RUN: opt < %s -passes=sample-profile -use-profiled-call-graph=1 -sample-profile-file=%S/Inputs/profile-context-order.prof -S | FileCheck %s -check-prefix=ICALL-INLINE 19de40f6d6SHongtao Yu 20bf317f66SHongtao Yu;; When a cycle is formed by profiled edges between _Z5funcBi and _Z8funcLeafi, 21bf317f66SHongtao Yu;; the function processing order matters. Without considering call edge weights 22bf317f66SHongtao Yu;; _Z8funcLeafi can be processed before _Z5funcBi, thus leads to suboptimal 23bf317f66SHongtao Yu;; inlining. 24bf317f66SHongtao Yu; RUN: opt < %s -passes=sample-profile -use-profiled-call-graph=1 -sort-profiled-scc-member=0 -sample-profile-file=%S/Inputs/profile-context-order-scc.prof -S | FileCheck %s -check-prefix=NOINLINEB 25bf317f66SHongtao Yu; RUN: opt < %s -passes=sample-profile -use-profiled-call-graph=1 -sort-profiled-scc-member=1 -sample-profile-file=%S/Inputs/profile-context-order-scc.prof -S | FileCheck %s -check-prefix=INLINEB 26bf317f66SHongtao Yu 27bf317f66SHongtao Yu 28de40f6d6SHongtao Yu@factor = dso_local global i32 3, align 4, !dbg !0 290271ae65SFangrui Song@fp = dso_local global ptr null, align 8 30de40f6d6SHongtao Yu 31*eecb8c5fSArthur Eubanks; INLINE: define dso_local i32 @_Z5funcAi 32*eecb8c5fSArthur Eubanks; INLINE-NOT: call i32 @_Z8funcLeafi 33*eecb8c5fSArthur Eubanks; NOINLINE: define dso_local i32 @_Z5funcAi 34*eecb8c5fSArthur Eubanks; NOINLINE: call i32 @_Z8funcLeafi 35*eecb8c5fSArthur Eubanks; ICALL-INLINE: define dso_local i32 @_Z5funcAi 36*eecb8c5fSArthur Eubanks; ICALL-INLINE: call i32 @_Z3foo 37*eecb8c5fSArthur Eubanks; INLINEB: define dso_local i32 @_Z5funcBi 38*eecb8c5fSArthur Eubanks; INLINEB-NOT: call i32 @_Z8funcLeafi 39*eecb8c5fSArthur Eubanks; NOINLINEB: define dso_local i32 @_Z5funcBi 40*eecb8c5fSArthur Eubanks; NOINLINEB: call i32 @_Z8funcLeafi 41*eecb8c5fSArthur Eubanksdefine dso_local i32 @_Z5funcAi(i32 %x) local_unnamed_addr #0 !dbg !40 { 42*eecb8c5fSArthur Eubanksentry: 43*eecb8c5fSArthur Eubanks %add = add nsw i32 %x, 100000, !dbg !44 44*eecb8c5fSArthur Eubanks %0 = load ptr, ptr @fp, align 8 45*eecb8c5fSArthur Eubanks %call = call i32 %0(i32 8), !dbg !45 46*eecb8c5fSArthur Eubanks %call1 = tail call i32 @_Z8funcLeafi(i32 %add), !dbg !46 47*eecb8c5fSArthur Eubanks ret i32 %call, !dbg !46 48*eecb8c5fSArthur Eubanks} 49*eecb8c5fSArthur Eubanks 50de40f6d6SHongtao Yudefine dso_local i32 @main() local_unnamed_addr #0 !dbg !18 { 51de40f6d6SHongtao Yuentry: 520271ae65SFangrui Song store ptr @_Z3fibi, ptr @fp, align 8, !dbg !25 53de40f6d6SHongtao Yu br label %for.body, !dbg !25 54de40f6d6SHongtao Yu 55de40f6d6SHongtao Yufor.cond.cleanup: ; preds = %for.body 56de40f6d6SHongtao Yu ret i32 %add3, !dbg !27 57de40f6d6SHongtao Yu 58de40f6d6SHongtao Yufor.body: ; preds = %for.body, %entry 59de40f6d6SHongtao Yu %x.011 = phi i32 [ 300000, %entry ], [ %dec, %for.body ] 60de40f6d6SHongtao Yu %r.010 = phi i32 [ 0, %entry ], [ %add3, %for.body ] 61de40f6d6SHongtao Yu %call = tail call i32 @_Z5funcBi(i32 %x.011), !dbg !32 62de40f6d6SHongtao Yu %add = add nuw nsw i32 %x.011, 1, !dbg !31 63de40f6d6SHongtao Yu %call1 = tail call i32 @_Z5funcAi(i32 %add), !dbg !28 64de40f6d6SHongtao Yu %add2 = add i32 %call, %r.010, !dbg !34 65de40f6d6SHongtao Yu %add3 = add i32 %add2, %call1, !dbg !35 66de40f6d6SHongtao Yu %dec = add nsw i32 %x.011, -1, !dbg !36 67de40f6d6SHongtao Yu %cmp = icmp eq i32 %x.011, 0, !dbg !38 68de40f6d6SHongtao Yu br i1 %cmp, label %for.cond.cleanup, label %for.body, !dbg !25 69de40f6d6SHongtao Yu} 70de40f6d6SHongtao Yu 71de40f6d6SHongtao Yu; INLINE: define dso_local i32 @_Z8funcLeafi 72de40f6d6SHongtao Yu; NOINLINE: define dso_local i32 @_Z8funcLeafi 73de40f6d6SHongtao Yu; ICALL-INLINE: define dso_local i32 @_Z8funcLeafi 74de40f6d6SHongtao Yu; ICALL-NOINLINE: define dso_local i32 @_Z8funcLeafi 75de40f6d6SHongtao Yudefine dso_local i32 @_Z8funcLeafi(i32 %x) local_unnamed_addr #1 !dbg !54 { 76de40f6d6SHongtao Yuentry: 77de40f6d6SHongtao Yu %cmp = icmp sgt i32 %x, 0, !dbg !57 78de40f6d6SHongtao Yu br i1 %cmp, label %while.body, label %while.cond2.preheader, !dbg !59 79de40f6d6SHongtao Yu 80de40f6d6SHongtao Yuwhile.cond2.preheader: ; preds = %entry 81de40f6d6SHongtao Yu %cmp313 = icmp slt i32 %x, 0, !dbg !60 82de40f6d6SHongtao Yu br i1 %cmp313, label %while.body4, label %if.end, !dbg !63 83de40f6d6SHongtao Yu 84de40f6d6SHongtao Yuwhile.body: ; preds = %while.body, %entry 85de40f6d6SHongtao Yu %x.addr.016 = phi i32 [ %sub, %while.body ], [ %x, %entry ] 860271ae65SFangrui Song %tmp = load volatile i32, ptr @factor, align 4, !dbg !64 87de40f6d6SHongtao Yu %call = tail call i32 @_Z5funcAi(i32 %tmp), !dbg !67 88de40f6d6SHongtao Yu %sub = sub nsw i32 %x.addr.016, %call, !dbg !68 89de40f6d6SHongtao Yu %cmp1 = icmp sgt i32 %sub, 0, !dbg !69 90de40f6d6SHongtao Yu br i1 %cmp1, label %while.body, label %if.end, !dbg !71 91de40f6d6SHongtao Yu 92de40f6d6SHongtao Yuwhile.body4: ; preds = %while.body4, %while.cond2.preheader 93de40f6d6SHongtao Yu %x.addr.114 = phi i32 [ %add, %while.body4 ], [ %x, %while.cond2.preheader ] 940271ae65SFangrui Song %tmp1 = load volatile i32, ptr @factor, align 4, !dbg !72 95de40f6d6SHongtao Yu %call5 = tail call i32 @_Z5funcBi(i32 %tmp1), !dbg !74 96de40f6d6SHongtao Yu %add = add nsw i32 %call5, %x.addr.114, !dbg !75 97de40f6d6SHongtao Yu %cmp3 = icmp slt i32 %add, 0, !dbg !60 98de40f6d6SHongtao Yu br i1 %cmp3, label %while.body4, label %if.end, !dbg !63 99de40f6d6SHongtao Yu 100de40f6d6SHongtao Yuif.end: ; preds = %while.body4, %while.body, %while.cond2.preheader 101de40f6d6SHongtao Yu %x.addr.2 = phi i32 [ 0, %while.cond2.preheader ], [ %sub, %while.body ], [ %add, %while.body4 ] 102de40f6d6SHongtao Yu ret i32 %x.addr.2, !dbg !76 103de40f6d6SHongtao Yu} 104de40f6d6SHongtao Yu 105de40f6d6SHongtao Yudefine dso_local i32 @_Z5funcBi(i32 %x) local_unnamed_addr #0 !dbg !47 { 106de40f6d6SHongtao Yuentry: 107de40f6d6SHongtao Yu %sub = add nsw i32 %x, -100000, !dbg !51 108de40f6d6SHongtao Yu %call = tail call i32 @_Z8funcLeafi(i32 %sub), !dbg !52 109de40f6d6SHongtao Yu ret i32 %call, !dbg !53 110de40f6d6SHongtao Yu} 111de40f6d6SHongtao Yu 112de40f6d6SHongtao Yudefine dso_local i32 @_Z3fibi(i32 %x) local_unnamed_addr #1 !dbg !77 { 113de40f6d6SHongtao Yuentry: 114de40f6d6SHongtao Yu %sub = add nsw i32 %x, -100000, !dbg !78 115de40f6d6SHongtao Yu %call = tail call i32 @_Z3foo(i32 %sub), !dbg !78 116de40f6d6SHongtao Yu ret i32 %sub, !dbg !78 117de40f6d6SHongtao Yu} 118de40f6d6SHongtao Yu 119de40f6d6SHongtao Yudeclare i32 @_Z3foo(i32) 120de40f6d6SHongtao Yu 1214ab3041aSserge-sans-pailleattributes #0 = { nofree noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile" } 1224ab3041aSserge-sans-pailleattributes #1 = { nofree nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile" } 123de40f6d6SHongtao Yu 124de40f6d6SHongtao Yu!llvm.dbg.cu = !{!2} 125de40f6d6SHongtao Yu!llvm.module.flags = !{!14, !15, !16} 126de40f6d6SHongtao Yu!llvm.ident = !{!17} 127de40f6d6SHongtao Yu 128de40f6d6SHongtao Yu!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 129de40f6d6SHongtao Yu!1 = distinct !DIGlobalVariable(name: "factor", scope: !2, file: !3, line: 21, type: !13, isLocal: false, isDefinition: true) 130de40f6d6SHongtao Yu!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) 131de40f6d6SHongtao Yu!3 = !DIFile(filename: "merged.cpp", directory: "/local/autofdo") 132de40f6d6SHongtao Yu!4 = !{} 133de40f6d6SHongtao Yu!5 = !{!6, !10, !11} 134de40f6d6SHongtao Yu!6 = !DISubprogram(name: "funcA", linkageName: "_Z5funcAi", scope: !3, file: !3, line: 6, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4) 135de40f6d6SHongtao Yu!7 = !DISubroutineType(types: !8) 136de40f6d6SHongtao Yu!8 = !{!9, !9} 137de40f6d6SHongtao Yu!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 138de40f6d6SHongtao Yu!10 = !DISubprogram(name: "funcB", linkageName: "_Z5funcBi", scope: !3, file: !3, line: 7, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4) 139de40f6d6SHongtao Yu!11 = !DISubprogram(name: "funcLeaf", linkageName: "_Z8funcLeafi", scope: !3, file: !3, line: 22, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4) 140de40f6d6SHongtao Yu!12 = !{!0} 141de40f6d6SHongtao Yu!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !9) 142de40f6d6SHongtao Yu!14 = !{i32 7, !"Dwarf Version", i32 4} 143de40f6d6SHongtao Yu!15 = !{i32 2, !"Debug Info Version", i32 3} 144de40f6d6SHongtao Yu!16 = !{i32 1, !"wchar_size", i32 4} 145de40f6d6SHongtao Yu!17 = !{!"clang version 11.0.0"} 146de40f6d6SHongtao Yu!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) 147de40f6d6SHongtao Yu!19 = !DISubroutineType(types: !20) 148de40f6d6SHongtao Yu!20 = !{!9} 149de40f6d6SHongtao Yu!21 = !{!22, !23} 150de40f6d6SHongtao Yu!22 = !DILocalVariable(name: "r", scope: !18, file: !3, line: 12, type: !9) 151de40f6d6SHongtao Yu!23 = !DILocalVariable(name: "x", scope: !24, file: !3, line: 13, type: !9) 152de40f6d6SHongtao Yu!24 = distinct !DILexicalBlock(scope: !18, file: !3, line: 13, column: 3) 153de40f6d6SHongtao Yu!25 = !DILocation(line: 13, column: 3, scope: !26) 154de40f6d6SHongtao Yu!26 = !DILexicalBlockFile(scope: !24, file: !3, discriminator: 2) 155de40f6d6SHongtao Yu!27 = !DILocation(line: 17, column: 3, scope: !18) 156de40f6d6SHongtao Yu!28 = !DILocation(line: 14, column: 10, scope: !29) 157de40f6d6SHongtao Yu!29 = distinct !DILexicalBlock(scope: !30, file: !3, line: 13, column: 37) 158de40f6d6SHongtao Yu!30 = distinct !DILexicalBlock(scope: !24, file: !3, line: 13, column: 3) 159de40f6d6SHongtao Yu!31 = !DILocation(line: 14, column: 29, scope: !29) 160de40f6d6SHongtao Yu!32 = !DILocation(line: 14, column: 21, scope: !33) 161de40f6d6SHongtao Yu!33 = !DILexicalBlockFile(scope: !29, file: !3, discriminator: 2) 162de40f6d6SHongtao Yu!34 = !DILocation(line: 14, column: 19, scope: !29) 163de40f6d6SHongtao Yu!35 = !DILocation(line: 14, column: 7, scope: !29) 164de40f6d6SHongtao Yu!36 = !DILocation(line: 13, column: 33, scope: !37) 165de40f6d6SHongtao Yu!37 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 6) 166de40f6d6SHongtao Yu!38 = !DILocation(line: 13, column: 26, scope: !39) 167de40f6d6SHongtao Yu!39 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 2) 168de40f6d6SHongtao Yu!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) 169de40f6d6SHongtao Yu!44 = !DILocation(line: 26, column: 22, scope: !40) 170de40f6d6SHongtao Yu!45 = !DILocation(line: 28, column: 11, scope: !40) 171de40f6d6SHongtao Yu!46 = !DILocation(line: 27, column: 3, scope: !40) 172de40f6d6SHongtao Yu!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) 173de40f6d6SHongtao Yu!51 = !DILocation(line: 33, column: 22, scope: !47) 174de40f6d6SHongtao Yu!52 = !DILocation(line: 33, column: 11, scope: !47) 175de40f6d6SHongtao Yu!53 = !DILocation(line: 35, column: 3, scope: !47) 176de40f6d6SHongtao Yu!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) 177de40f6d6SHongtao Yu!57 = !DILocation(line: 49, column: 9, scope: !58) 178de40f6d6SHongtao Yu!58 = distinct !DILexicalBlock(scope: !54, file: !3, line: 49, column: 7) 179de40f6d6SHongtao Yu!59 = !DILocation(line: 49, column: 7, scope: !54) 180de40f6d6SHongtao Yu!60 = !DILocation(line: 58, column: 14, scope: !61) 181de40f6d6SHongtao Yu!61 = !DILexicalBlockFile(scope: !62, file: !3, discriminator: 2) 182de40f6d6SHongtao Yu!62 = distinct !DILexicalBlock(scope: !58, file: !3, line: 56, column: 8) 183de40f6d6SHongtao Yu!63 = !DILocation(line: 58, column: 5, scope: !61) 184de40f6d6SHongtao Yu!64 = !DILocation(line: 52, column: 16, scope: !65) 185de40f6d6SHongtao Yu!65 = distinct !DILexicalBlock(scope: !66, file: !3, line: 51, column: 19) 186de40f6d6SHongtao Yu!66 = distinct !DILexicalBlock(scope: !58, file: !3, line: 49, column: 14) 187de40f6d6SHongtao Yu!67 = !DILocation(line: 52, column: 12, scope: !65) 188de40f6d6SHongtao Yu!68 = !DILocation(line: 52, column: 9, scope: !65) 189de40f6d6SHongtao Yu!69 = !DILocation(line: 51, column: 14, scope: !70) 190de40f6d6SHongtao Yu!70 = !DILexicalBlockFile(scope: !66, file: !3, discriminator: 2) 191de40f6d6SHongtao Yu!71 = !DILocation(line: 51, column: 5, scope: !70) 192de40f6d6SHongtao Yu!72 = !DILocation(line: 59, column: 16, scope: !73) 193de40f6d6SHongtao Yu!73 = distinct !DILexicalBlock(scope: !62, file: !3, line: 58, column: 19) 194de40f6d6SHongtao Yu!74 = !DILocation(line: 59, column: 12, scope: !73) 195de40f6d6SHongtao Yu!75 = !DILocation(line: 59, column: 9, scope: !73) 196de40f6d6SHongtao Yu!76 = !DILocation(line: 63, column: 3, scope: !54) 197de40f6d6SHongtao Yu!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) 198de40f6d6SHongtao Yu!78 = !DILocation(line: 33, column: 22, scope: !77) 199