xref: /llvm-project/llvm/test/Transforms/PGOProfile/coverage.ll (revision 2d69827c5c754f0eca98e497ecf0e52ed54b4fd3)
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
3
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
6target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7target triple = "x86_64-unknown-linux-gnu"
8
9; CHECK-LABEL: @foo()
10; USE-SAME: !prof ![[HOT:[0-9]+]]
11define void @foo() {
12; CHECK-LABEL: entry:
13entry:
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]+]]
18
19; CHECK-LABEL: if.then:
20if.then:
21  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
22  br label %if.end
23
24; CHECK-LABEL: if.else:
25if.else:
26  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
27  br label %if.end
28
29; CHECK-LABEL: if.end:
30if.end:
31  ret void
32}
33
34; CHECK-LABEL: @bar()
35; USE-SAME: !prof ![[HOT:[0-9]+]]
36define void @bar() {
37; CHECK-LABEL: entry:
38entry:
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]+]]
43
44; CHECK-LABEL: if.then:
45if.then:
46  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
47  br label %if.end
48
49; CHECK-LABEL: if.end:
50if.end:
51  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
52  ret void
53}
54
55; CHECK-LABEL: @goo()
56; USE-SAME: !prof ![[HOT:[0-9]+]]
57define void @goo() {
58; CHECK-LABEL: entry:
59entry:
60  ; GEN: call void @llvm.instrprof.cover({{.*}})
61  ret void
62}
63
64; CHECK-LABEL: @loop()
65; USE-SAME: !prof ![[HOT:[0-9]+]]
66define void @loop() {
67; CHECK-LABEL: entry:
68entry:
69  ; GEN: call void @llvm.instrprof.cover({{.*}})
70  br label %while
71while:
72  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
73  br label %while
74}
75
76; CHECK-LABEL: @hoo(
77; USE-SAME: !prof ![[HOT:[0-9]+]]
78define void @hoo(i32 %a) #0 {
79; CHECK-LABEL: entry:
80entry:
81  ; ENTRY: call void @llvm.instrprof.cover({{.*}})
82  %a.addr = alloca i32, align 4
83  %i = alloca i32, align 4
84  store i32 %a, ptr %a.addr, align 4
85  %0 = load i32, ptr %a.addr, align 4
86  %rem = srem i32 %0, 2
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]]
90
91; CHECK-LABEL: if.then:
92if.then:                                          ; preds = %entry
93  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
94  br label %if.end
95
96; CHECK-LABEL: if.else:
97if.else:                                          ; preds = %entry
98  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
99  br label %if.end
100
101; CHECK-LABEL: if.end:
102if.end:                                           ; preds = %if.else, %if.then
103  store i32 1, ptr %i, align 4
104  br label %for.cond
105
106; CHECK-LABEL: for.cond:
107for.cond:                                         ; preds = %for.inc, %if.end
108  %1 = load i32, ptr %i, align 4
109  %2 = load i32, ptr %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]]
113
114; CHECK-LABEL: for.body:
115for.body:                                         ; preds = %for.cond
116  %3 = load i32, ptr %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]]
121
122; CHECK-LABEL: if.then4:
123if.then4:                                         ; preds = %for.body
124  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
125  br label %if.end10
126
127; CHECK-LABEL: if.else5:
128if.else5:                                         ; preds = %for.body
129  %4 = load i32, ptr %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]]
134
135; CHECK-LABEL: if.then8:
136if.then8:                                         ; preds = %if.else5
137  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
138  br label %return
139
140; CHECK-LABEL: if.end9:
141if.end9:                                          ; preds = %if.else5
142  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
143  br label %if.end10
144
145; CHECK-LABEL: if.end10:
146if.end10:                                         ; preds = %if.end9, %if.then4
147  br label %for.inc
148
149; CHECK-LABEL: for.inc:
150for.inc:                                          ; preds = %if.end10
151  %5 = load i32, ptr %i, align 4
152  %inc = add nsw i32 %5, 1
153  store i32 %inc, ptr %i, align 4
154  br label %for.cond
155
156; CHECK-LABEL: for.end:
157for.end:                                          ; preds = %for.cond
158  ; BLOCK: call void @llvm.instrprof.cover({{.*}})
159  br label %return
160
161; CHECK-LABEL: return:
162return:                                           ; preds = %for.end, %if.then8
163  ret void
164}
165
166declare i1 @choice()
167
168; GEN: declare void @llvm.instrprof.cover({{.*}})
169
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}
173