1cee313d2SEric Christopher; REQUIRES: x86-registered-target
2cee313d2SEric Christopher
3*de620f5bSRong Xu; RUN: opt -passes='thinlto-pre-link<O2>' --cs-profilegen-file=alloc -cspgo-kind=cspgo-instr-gen-pipeline -module-summary %s -o %t1.bc
4*de620f5bSRong Xu; RUN: opt -passes='thinlto-pre-link<O2>' --cs-profilegen-file=alloc -cspgo-kind=cspgo-instr-gen-pipeline -module-summary %S/Inputs/thinlto_cspgo_bar_gen.ll -o %t2.bc
5cee313d2SEric Christopher; RUN: llvm-lto2 run -lto-cspgo-profile-file=alloc -lto-cspgo-gen -save-temps -o %t %t1.bc %t2.bc \
6cee313d2SEric Christopher; RUN:   -r=%t1.bc,foo,pl \
7cee313d2SEric Christopher; RUN:   -r=%t1.bc,bar,l \
8cee313d2SEric Christopher; RUN:   -r=%t1.bc,main,plx \
9cee313d2SEric Christopher; RUN:   -r=%t1.bc,__llvm_profile_filename,plx \
10cee313d2SEric Christopher; RUN:   -r=%t1.bc,__llvm_profile_raw_version,plx \
11cee313d2SEric Christopher; RUN:   -r=%t2.bc,bar,pl \
12cee313d2SEric Christopher; RUN:   -r=%t2.bc,odd,pl \
13cee313d2SEric Christopher; RUN:   -r=%t2.bc,even,pl \
14cee313d2SEric Christopher; RUN:   -r=%t2.bc,__llvm_profile_filename,x \
15cee313d2SEric Christopher; RUN:   -r=%t2.bc,__llvm_profile_raw_version,x
16*de620f5bSRong Xu; RUN: llvm-dis %t.1.4.opt.bc -o - | FileCheck %s --check-prefixes=CSGEN,PREVAILING
17*de620f5bSRong Xu; RUN: llvm-dis %t.2.4.opt.bc -o - | FileCheck %s --check-prefixes=CSGEN,NOPREVAILING
18cee313d2SEric Christopher
19*de620f5bSRong Xu;; Prevailing __llvm_profile_raw_version is kept by LTO.
20*de620f5bSRong Xu; PREVAILING: @__llvm_profile_raw_version = constant i64
21*de620f5bSRong Xu
22*de620f5bSRong Xu;; Non-prevailing __llvm_profile_raw_version is discarded by LTO. Ensure the
23*de620f5bSRong Xu;; declaration is retained.
24*de620f5bSRong Xu; NOPREVAILING: @__llvm_profile_raw_version = external constant i64
25cee313d2SEric Christopher; CSGEN: @__profc_
26cee313d2SEric Christopher; CSGEN: @__profd_
27cee313d2SEric Christopher
28cee313d2SEric Christophersource_filename = "cspgo.c"
297b1d7937SAmy Huangtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
30cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu"
31cee313d2SEric Christopher
32cee313d2SEric Christopherdefine dso_local void @foo() #0 !prof !29 {
33cee313d2SEric Christopherentry:
34cee313d2SEric Christopher  br label %for.body
35cee313d2SEric Christopher
36cee313d2SEric Christopherfor.body:
37cee313d2SEric Christopher  %i.06 = phi i32 [ 0, %entry ], [ %add1, %for.body ]
38cee313d2SEric Christopher  tail call void @bar(i32 %i.06)
39cee313d2SEric Christopher  %add = or i32 %i.06, 1
40cee313d2SEric Christopher  tail call void @bar(i32 %add)
41cee313d2SEric Christopher  %add1 = add nuw nsw i32 %i.06, 2
42cee313d2SEric Christopher  %cmp = icmp ult i32 %add1, 200000
43cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end, !prof !30
44cee313d2SEric Christopher
45cee313d2SEric Christopherfor.end:
46cee313d2SEric Christopher  ret void
47cee313d2SEric Christopher}
48cee313d2SEric Christopher
49cee313d2SEric Christopherdeclare dso_local void @bar(i32)
50cee313d2SEric Christopher
51cee313d2SEric Christopherdefine dso_local i32 @main() !prof !29 {
52cee313d2SEric Christopherentry:
53cee313d2SEric Christopher  tail call void @foo()
54cee313d2SEric Christopher  ret i32 0
55cee313d2SEric Christopher}
56cee313d2SEric Christopher
57cee313d2SEric Christopherattributes #0 = { "target-cpu"="x86-64" }
58cee313d2SEric Christopher
59cee313d2SEric Christopher!llvm.module.flags = !{!0, !1}
60cee313d2SEric Christopher
61cee313d2SEric Christopher!0 = !{i32 1, !"wchar_size", i32 4}
62cee313d2SEric Christopher!1 = !{i32 1, !"ProfileSummary", !2}
63cee313d2SEric Christopher!2 = !{!3, !4, !5, !6, !7, !8, !9, !10}
64cee313d2SEric Christopher!3 = !{!"ProfileFormat", !"InstrProf"}
65cee313d2SEric Christopher!4 = !{!"TotalCount", i64 500002}
66cee313d2SEric Christopher!5 = !{!"MaxCount", i64 200000}
67cee313d2SEric Christopher!6 = !{!"MaxInternalCount", i64 100000}
68cee313d2SEric Christopher!7 = !{!"MaxFunctionCount", i64 200000}
69cee313d2SEric Christopher!8 = !{!"NumCounts", i64 6}
70cee313d2SEric Christopher!9 = !{!"NumFunctions", i64 4}
71cee313d2SEric Christopher!10 = !{!"DetailedSummary", !11}
72cee313d2SEric Christopher!11 = !{!12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27}
73cee313d2SEric Christopher!12 = !{i32 10000, i64 200000, i32 1}
74cee313d2SEric Christopher!13 = !{i32 100000, i64 200000, i32 1}
75cee313d2SEric Christopher!14 = !{i32 200000, i64 200000, i32 1}
76cee313d2SEric Christopher!15 = !{i32 300000, i64 200000, i32 1}
77cee313d2SEric Christopher!16 = !{i32 400000, i64 200000, i32 1}
78cee313d2SEric Christopher!17 = !{i32 500000, i64 100000, i32 4}
79cee313d2SEric Christopher!18 = !{i32 600000, i64 100000, i32 4}
80cee313d2SEric Christopher!19 = !{i32 700000, i64 100000, i32 4}
81cee313d2SEric Christopher!20 = !{i32 800000, i64 100000, i32 4}
82cee313d2SEric Christopher!21 = !{i32 900000, i64 100000, i32 4}
83cee313d2SEric Christopher!22 = !{i32 950000, i64 100000, i32 4}
84cee313d2SEric Christopher!23 = !{i32 990000, i64 100000, i32 4}
85cee313d2SEric Christopher!24 = !{i32 999000, i64 100000, i32 4}
86cee313d2SEric Christopher!25 = !{i32 999900, i64 100000, i32 4}
87cee313d2SEric Christopher!26 = !{i32 999990, i64 100000, i32 4}
88cee313d2SEric Christopher!27 = !{i32 999999, i64 1, i32 6}
89cee313d2SEric Christopher!29 = !{!"function_entry_count", i64 1}
90cee313d2SEric Christopher!30 = !{!"branch_weights", i32 100000, i32 1}
91