Skip to content

Commit abfdcb6

Browse files
committed
[PGO] Test graceful handling of zero profile counts
This crashed before making fixFuncEntryCount gracefully handle zero counts.
1 parent 83a55a2 commit abfdcb6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:ir
2+
test_no_entry_block_counter
3+
431494656217155589
4+
3
5+
0
6+
0
7+
1
8+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llvm-profdata merge %S/Inputs/fix_entry_count_sampled.proftext -o %t.profdata
2+
; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
3+
4+
; Instrumentation PGO sampling makes corrupt looking counters possible. This
5+
; tests one extreme case:
6+
; Test loading zero profile counts for all instrumented blocks while the entry
7+
; block is not instrumented. Additionally include a non-zero profile count for
8+
; a select instruction, which prevents short circuiting the PGO application.
9+
10+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
11+
target triple = "x86_64-unknown-linux-gnu"
12+
13+
define i32 @test_no_entry_block_counter(i32 %n) {
14+
; USE: define i32 @test_no_entry_block_counter(i32 %n)
15+
; USE-SAME: !prof ![[ENTRY_COUNT:[0-9]*]]
16+
entry:
17+
%cmp = icmp slt i32 42, %n
18+
br i1 %cmp, label %tail1, label %tail2
19+
tail1:
20+
%ret = select i1 true, i32 %n, i32 42
21+
; USE: %ret = select i1 true, i32 %n, i32 42
22+
; USE-SAME: !prof ![[BW_FOR_SELECT:[0-9]+]]
23+
ret i32 %ret
24+
tail2:
25+
ret i32 42
26+
}
27+
; USE: ![[ENTRY_COUNT]] = !{!"function_entry_count", i64 1}
28+
; USE: ![[BW_FOR_SELECT]] = !{!"branch_weights", i32 1, i32 0}

0 commit comments

Comments
 (0)