1 ; RUN: opt < %s -passes=pgo-instr-gen -pgo-function-entry-coverage -S | FileCheck %s --implicit-check-not="instrprof.cover" --check-prefixes=CHECK,GEN,ENTRY
2 ; RUN: opt < %s -passes=pgo-instr-gen -pgo-block-coverage -S | FileCheck %s --implicit-check-not="instrprof.cover" --check-prefixes=CHECK,GEN,BLOCK
4 ; RUN: llvm-profdata merge %S/Inputs/coverage.proftext -o %t.profdata
5 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefixes=CHECK,USE
6 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux-gnu"
10 ; USE-SAME: !prof ![[HOT:[0-9]+]]
14 ; ENTRY: call void @llvm.instrprof.cover({{.*}})
15 %c = call i1 @choice()
16 br i1 %c, label %if.then, label %if.else
17 ; USE: br i1 %c, label %if.then, label %if.else, !prof ![[WEIGHTS0:[0-9]+]]
19 ; CHECK-LABEL: if.then:
21 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
24 ; CHECK-LABEL: if.else:
26 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
29 ; CHECK-LABEL: if.end:
35 ; USE-SAME: !prof ![[HOT:[0-9]+]]
39 ; ENTRY: call void @llvm.instrprof.cover({{.*}})
40 %c = call i1 @choice()
41 br i1 %c, label %if.then, label %if.end
42 ; USE: br i1 %c, label %if.then, label %if.end, !prof ![[WEIGHTS1:[0-9]+]]
44 ; CHECK-LABEL: if.then:
46 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
49 ; CHECK-LABEL: if.end:
51 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
56 ; USE-SAME: !prof ![[HOT:[0-9]+]]
60 ; GEN: call void @llvm.instrprof.cover({{.*}})
64 ; CHECK-LABEL: @loop()
65 ; USE-SAME: !prof ![[HOT:[0-9]+]]
69 ; GEN: call void @llvm.instrprof.cover({{.*}})
72 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
77 ; USE-SAME: !prof ![[HOT:[0-9]+]]
78 define void @hoo(i32 %a) #0 {
81 ; ENTRY: call void @llvm.instrprof.cover({{.*}})
82 %a.addr = alloca i32, align 4
83 %i = alloca i32, align 4
84 store i32 %a, i32* %a.addr, align 4
85 %0 = load i32, i32* %a.addr, align 4
87 %cmp = icmp eq i32 %rem, 0
88 br i1 %cmp, label %if.then, label %if.else
89 ; USE: br i1 %cmp, label %if.then, label %if.else, !prof ![[WEIGHTS1]]
91 ; CHECK-LABEL: if.then:
92 if.then: ; preds = %entry
93 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
96 ; CHECK-LABEL: if.else:
97 if.else: ; preds = %entry
98 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
101 ; CHECK-LABEL: if.end:
102 if.end: ; preds = %if.else, %if.then
103 store i32 1, i32* %i, align 4
106 ; CHECK-LABEL: for.cond:
107 for.cond: ; preds = %for.inc, %if.end
108 %1 = load i32, i32* %i, align 4
109 %2 = load i32, i32* %a.addr, align 4
110 %cmp1 = icmp slt i32 %1, %2
111 br i1 %cmp1, label %for.body, label %for.end
112 ; USE: br i1 %cmp1, label %for.body, label %for.end, !prof ![[WEIGHTS1]]
114 ; CHECK-LABEL: for.body:
115 for.body: ; preds = %for.cond
116 %3 = load i32, i32* %a.addr, align 4
117 %rem2 = srem i32 %3, 3
118 %cmp3 = icmp eq i32 %rem2, 0
119 br i1 %cmp3, label %if.then4, label %if.else5
120 ; USE: br i1 %cmp3, label %if.then4, label %if.else5, !prof ![[WEIGHTS0]]
122 ; CHECK-LABEL: if.then4:
123 if.then4: ; preds = %for.body
124 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
127 ; CHECK-LABEL: if.else5:
128 if.else5: ; preds = %for.body
129 %4 = load i32, i32* %a.addr, align 4
130 %rem6 = srem i32 %4, 1001
131 %cmp7 = icmp eq i32 %rem6, 0
132 br i1 %cmp7, label %if.then8, label %if.end9
133 ; USE: br i1 %cmp7, label %if.then8, label %if.end9, !prof ![[WEIGHTS1]]
135 ; CHECK-LABEL: if.then8:
136 if.then8: ; preds = %if.else5
137 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
140 ; CHECK-LABEL: if.end9:
141 if.end9: ; preds = %if.else5
142 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
145 ; CHECK-LABEL: if.end10:
146 if.end10: ; preds = %if.end9, %if.then4
149 ; CHECK-LABEL: for.inc:
150 for.inc: ; preds = %if.end10
151 %5 = load i32, i32* %i, align 4
152 %inc = add nsw i32 %5, 1
153 store i32 %inc, i32* %i, align 4
156 ; CHECK-LABEL: for.end:
157 for.end: ; preds = %for.cond
158 ; BLOCK: call void @llvm.instrprof.cover({{.*}})
161 ; CHECK-LABEL: return:
162 return: ; preds = %for.end, %if.then8
168 ; GEN: declare void @llvm.instrprof.cover({{.*}})
170 ; USE-DAG: ![[HOT]] = !{!"function_entry_count", i64 10000}
171 ; USE-DAG: ![[WEIGHTS0]] = !{!"branch_weights", i32 1, i32 1}
172 ; USE-DAG: ![[WEIGHTS1]] = !{!"branch_weights", i32 1, i32 0}