1; Tests that hot callsite threshold is set to 0 artifically for thinlto-prelink pipeline. 2; 3; Function `sum` is annotated with inline cost -1 and function `sum1` is 4; annotated with inline cost 0, by function attribute `function-inline-cost`. 5; 6; `if.then` basic block is hot so the callsite threshold is set to 0. 7; `while.body.split` basic block is cold so threshold is calculated using 8; the rest of default heuristics, which should be sufficient to inline a 9; function with 0 cost. 10 11; RUN: opt < %s -pass-remarks=inline -pass-remarks-missed=inline -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -sample-profile-file=%S/Inputs/new-pm-thinlto-prelink-samplepgo-inline-threshold.prof -S | FileCheck %s 12 13; RUN: opt < %s -pass-remarks=inline -pass-remarks-missed=inline -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -sample-profile-file=%S/Inputs/new-pm-thinlto-prelink-samplepgo-inline-threshold.prof -S 2>&1 | FileCheck %s -check-prefix=REMARK 14 15; Original C++ test case 16; 17; #include <stdio.h> 18 19; int sum(int x, int y) { return x + y; } 20 21; int sum1(int x, int y) { return x + y; } 22 23; int main() { 24; int s, i = 0; 25; while (i++ < 20000 * 20000) { 26; if (i != 100) s = sum(i, s); 27; s = sum1(i, s); 28; } 29; printf("sum is %d\n", s); 30; return 0; 31; } 32; 33 34; REMARK: test.cc:14:9: '_Z4sum1ii' inlined into 'main' with (cost=0, threshold=45) at callsite main:4:9; 35; REMARK: test.cc:13:23: '_Z3sumii' inlined into 'main' with (cost=-1, threshold=0) at callsite main:3:23.2; 36; REMARK: test.cc:14:9: '_Z4sum1ii' not inlined into 'main' because too costly to inline (cost=0, threshold=0) 37 38; ModuleID = 'test.cc' 39source_filename = "test.cc" 40target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 41target triple = "x86_64-unknown-linux-gnu" 42 43@.str = constant [11 x i8] c"sum is %d\0A\00", align 1 44 45define i32 @_Z3sumii(i32 %x, i32 %y) "function-inline-cost"="-1" #0 !dbg !7 { 46entry: 47 %add = add nsw i32 %y, %x, !dbg !10 48 ret i32 %add, !dbg !11 49} 50 51define i32 @_Z4sum1ii(i32 %x, i32 %y) "function-inline-cost"="0" #0 !dbg !12 { 52entry: 53 %add = add nsw i32 %y, %x, !dbg !13 54 ret i32 %add, !dbg !14 55} 56 57define i32 @main() #0 !dbg !15 { 58entry: 59 br label %while.body, !dbg !16 60 61while.body: ; preds = %entry, %if.end 62 %inc14 = phi i32 [ 1, %entry ], [ %inc, %if.end ] 63 %s.013 = phi i32 [ undef, %entry ], [ %phi.call, %if.end ] 64 %cmp1.not = icmp eq i32 %inc14, 100, !dbg !17 65 br i1 %cmp1.not, label %while.body.split, label %if.then, !dbg !18 66 67while.body.split: ; preds = %while.body 68; CHECK-NOT: call noundef i32 @_Z4sum1ii 69 %call211 = call noundef i32 @_Z4sum1ii(i32 100, i32 %s.013), !dbg !19 70 br label %if.end, !dbg !18 71 72if.then: ; preds = %while.body 73; CHECK-NOT: call i32 @_Z3sumii 74; CHECK: call i32 @_Z4sum1ii 75 %call = call i32 @_Z3sumii(i32 %inc14, i32 %s.013), !dbg !20 76 %call212 = call i32 @_Z4sum1ii(i32 %inc14, i32 %call), !dbg !19 77 br label %if.end, !dbg !21 78 79if.end: ; preds = %while.body.split, %if.then 80 %phi.call = phi i32 [ %call211, %while.body.split ], [ %call212, %if.then ], !dbg !19 81 %inc = add i32 %inc14, 1, !dbg !22 82 %exitcond.not = icmp eq i32 %inc, 400000001, !dbg !23 83 br i1 %exitcond.not, label %while.end, label %while.body, !dbg !16, !llvm.loop !24 84 85while.end: ; preds = %if.end 86 %call3 = tail call i32 (ptr, ...) @printf(ptr dereferenceable(1) @.str, i32 %phi.call), !dbg !27 87 ret i32 0, !dbg !28 88} 89 90declare i32 @printf(ptr nocapture noundef readonly, ...) 91 92attributes #0 = {"use-sample-profile"} 93 94!llvm.dbg.cu = !{!0} 95!llvm.module.flags = !{!2, !3} 96 97!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 329fda39c507e8740978d10458451dcdb21563be)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None) 98!1 = !DIFile(filename: "test.cc", directory: "", checksumkind: CSK_MD5, checksum: "e8c44edbdcc2c41f9f891ac2b2ddd591") 99!2 = !{i32 7, !"Dwarf Version", i32 5} 100!3 = !{i32 2, !"Debug Info Version", i32 3} 101!7 = distinct !DISubprogram(name: "sum", scope: !1, file: !1, line: 6, type: !8, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !9) 102!8 = !DISubroutineType(types: !9) 103!9 = !{} 104!10 = !DILocation(line: 6, column: 60, scope: !7) 105!11 = !DILocation(line: 6, column: 51, scope: !7) 106!12 = distinct !DISubprogram(name: "sum1", scope: !1, file: !1, line: 8, type: !8, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !9) 107!13 = !DILocation(line: 8, column: 61, scope: !12) 108!14 = !DILocation(line: 8, column: 52, scope: !12) 109!15 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 10, type: !8, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !9) 110!16 = !DILocation(line: 12, column: 3, scope: !15) 111!17 = !DILocation(line: 13, column: 11, scope: !15) 112!18 = !DILocation(line: 13, column: 9, scope: !15) 113!19 = !DILocation(line: 14, column: 9, scope: !15) 114!20 = !DILocation(line: 13, column: 23, scope: !15) 115!21 = !DILocation(line: 13, column: 19, scope: !15) 116!22 = !DILocation(line: 12, column: 11, scope: !15) 117!23 = !DILocation(line: 12, column: 14, scope: !15) 118!24 = distinct !{!24, !16, !25, !26} 119!25 = !DILocation(line: 15, column: 3, scope: !15) 120!26 = !{!"llvm.loop.mustprogress"} 121!27 = !DILocation(line: 16, column: 3, scope: !15) 122!28 = !DILocation(line: 17, column: 3, scope: !15) 123