126 lines · plain
1; Tests that hot callsite threshold is set to 0 artifically for thinlto-prelink and lto-pre-link pipeline.2;3; Function `sum` is annotated with inline cost -1 and function `sum1` is4; 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 using8; the rest of default heuristics, which should be sufficient to inline a9; 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 %s12 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=REMARK14 15; RUN: opt < %s -pass-remarks=inline -pass-remarks-missed=inline -passes='lto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -sample-profile-file=%S/Inputs/new-pm-thinlto-prelink-samplepgo-inline-threshold.prof -S | FileCheck %s16 17; RUN: opt < %s -pass-remarks=inline -pass-remarks-missed=inline -passes='lto-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=REMARK18; Original C++ test case19;20; #include <stdio.h>21 22; int sum(int x, int y) { return x + y; }23 24; int sum1(int x, int y) { return x + y; }25 26; int main() {27; int s, i = 0;28; while (i++ < 20000 * 20000) {29; if (i != 100) s = sum(i, s);30; s = sum1(i, s);31; }32; printf("sum is %d\n", s);33; return 0;34; }35;36 37; REMARK: test.cc:14:9: '_Z4sum1ii' inlined into 'main' with (cost=0, threshold=45) at callsite main:4:9;38; REMARK: test.cc:13:23: '_Z3sumii' inlined into 'main' with (cost=-1, threshold=0) at callsite main:3:23.2;39; REMARK: test.cc:14:9: '_Z4sum1ii' not inlined into 'main' because too costly to inline (cost=0, threshold=0)40 41; ModuleID = 'test.cc'42source_filename = "test.cc"43target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"44target triple = "x86_64-unknown-linux-gnu"45 46@.str = constant [11 x i8] c"sum is %d\0A\00", align 147 48define i32 @_Z3sumii(i32 %x, i32 %y) "function-inline-cost"="-1" #0 !dbg !7 {49entry:50 %add = add nsw i32 %y, %x, !dbg !1051 ret i32 %add, !dbg !1152}53 54define i32 @_Z4sum1ii(i32 %x, i32 %y) "function-inline-cost"="0" #0 !dbg !12 {55entry:56 %add = add nsw i32 %y, %x, !dbg !1357 ret i32 %add, !dbg !1458}59 60define i32 @main() #0 !dbg !15 {61entry:62 br label %while.body, !dbg !1663 64while.body: ; preds = %entry, %if.end65 %inc14 = phi i32 [ 1, %entry ], [ %inc, %if.end ]66 %s.013 = phi i32 [ undef, %entry ], [ %phi.call, %if.end ]67 %cmp1.not = icmp eq i32 %inc14, 100, !dbg !1768 br i1 %cmp1.not, label %while.body.split, label %if.then, !dbg !1869 70while.body.split: ; preds = %while.body71; CHECK-NOT: call noundef i32 @_Z4sum1ii72 %call211 = call noundef i32 @_Z4sum1ii(i32 100, i32 %s.013), !dbg !1973 br label %if.end, !dbg !1874 75if.then: ; preds = %while.body76; CHECK-NOT: call i32 @_Z3sumii77; CHECK: call i32 @_Z4sum1ii78 %call = call i32 @_Z3sumii(i32 %inc14, i32 %s.013), !dbg !2079 %call212 = call i32 @_Z4sum1ii(i32 %inc14, i32 %call), !dbg !1980 br label %if.end, !dbg !2181 82if.end: ; preds = %while.body.split, %if.then83 %phi.call = phi i32 [ %call211, %while.body.split ], [ %call212, %if.then ], !dbg !1984 %inc = add i32 %inc14, 1, !dbg !2285 %exitcond.not = icmp eq i32 %inc, 400000001, !dbg !2386 br i1 %exitcond.not, label %while.end, label %while.body, !dbg !16, !llvm.loop !2487 88while.end: ; preds = %if.end89 %call3 = tail call i32 (ptr, ...) @printf(ptr dereferenceable(1) @.str, i32 %phi.call), !dbg !2790 ret i32 0, !dbg !2891}92 93declare i32 @printf(ptr nocapture noundef readonly, ...)94 95attributes #0 = {"use-sample-profile"}96 97!llvm.dbg.cu = !{!0}98!llvm.module.flags = !{!2, !3}99 100!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)101!1 = !DIFile(filename: "test.cc", directory: "", checksumkind: CSK_MD5, checksum: "e8c44edbdcc2c41f9f891ac2b2ddd591")102!2 = !{i32 7, !"Dwarf Version", i32 5}103!3 = !{i32 2, !"Debug Info Version", i32 3}104!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)105!8 = !DISubroutineType(types: !9)106!9 = !{}107!10 = !DILocation(line: 6, column: 60, scope: !7)108!11 = !DILocation(line: 6, column: 51, scope: !7)109!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)110!13 = !DILocation(line: 8, column: 61, scope: !12)111!14 = !DILocation(line: 8, column: 52, scope: !12)112!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)113!16 = !DILocation(line: 12, column: 3, scope: !15)114!17 = !DILocation(line: 13, column: 11, scope: !15)115!18 = !DILocation(line: 13, column: 9, scope: !15)116!19 = !DILocation(line: 14, column: 9, scope: !15)117!20 = !DILocation(line: 13, column: 23, scope: !15)118!21 = !DILocation(line: 13, column: 19, scope: !15)119!22 = !DILocation(line: 12, column: 11, scope: !15)120!23 = !DILocation(line: 12, column: 14, scope: !15)121!24 = distinct !{!24, !16, !25, !26}122!25 = !DILocation(line: 15, column: 3, scope: !15)123!26 = !{!"llvm.loop.mustprogress"}124!27 = !DILocation(line: 16, column: 3, scope: !15)125!28 = !DILocation(line: 17, column: 3, scope: !15)126