llvm.org GIT mirror llvm / 8a66c7e
[PGO] Fix insane counts due to nonreturn calls Summary: Since we don't break BBs for function calls. We might get some insane counts (wrap of unsigned) in the presence of noreturn calls. This patch sets these counts to zero instead of the wrapped number. Reviewers: davidxl Subscribers: xur, eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D27602 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289521 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 2 years ago
3 changed file(s) with 68 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
883883 }
884884 if (Count->CountValid) {
885885 if (Count->UnknownCountOutEdge == 1) {
886 uint64_t Total = Count->CountValue - sumEdgeCount(Count->OutEdges);
886 uint64_t Total = 0;
887 uint64_t OutSum = sumEdgeCount(Count->OutEdges);
888 // If the one of the successor block can early terminate (no-return),
889 // we can end up with situation where out edge sum count is larger as
890 // the source BB's count is collected by a post-dominated block.
891 if (Count->CountValue > OutSum)
892 Total = Count->CountValue - OutSum;
887893 setEdgeCount(Count->OutEdges, Total);
888894 Changes = true;
889895 }
890896 if (Count->UnknownCountInEdge == 1) {
891 uint64_t Total = Count->CountValue - sumEdgeCount(Count->InEdges);
897 uint64_t Total = 0;
898 uint64_t InSum = sumEdgeCount(Count->InEdges);
899 if (Count->CountValue > InSum)
900 Total = Count->CountValue - InSum;
892901 setEdgeCount(Count->InEdges, Total);
893902 Changes = true;
894903 }
0 # IR level Instrumentation Flag
1 :ir
2 foo
3 # Func Hash:
4 36496524737
5 # Num Counters:
6 3
7 # Counter Values:
8 20
9 21
10 0
0 ; RUN: llvm-profdata merge %S/Inputs/noreturncall.proftext -o %t.profdata
1 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -debug-only=pgo-instrumentation 2>&1 | FileCheck %s --check-prefix=USE
2 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S -debug-only=pgo-instrumentation 2>&1 | FileCheck %s --check-prefix=USE
3
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
6
7 declare i32 @bar0(i32)
8
9 define i32 @bar2(i32 %i) {
10 entry:
11 unreachable
12 }
13
14 define i32 @foo(i32 %i, i32 %j, i32 %k) {
15 entry:
16 %cmp = icmp slt i32 %i, 999
17 br i1 %cmp, label %if.then, label %if.end
18
19 if.then:
20 %call = call i32 @bar0(i32 %i)
21 br label %if.end
22
23 if.end:
24 %ret.0 = phi i32 [ %call, %if.then ], [ 0, %entry ]
25 %cmp1 = icmp sgt i32 %j, 1000
26 %cmp3 = icmp sgt i32 %k, 99
27 %or.cond = and i1 %cmp1, %cmp3
28 br i1 %or.cond, label %if.then4, label %if.end7
29
30 if.then4:
31 %call5 = call i32 @bar2(i32 undef)
32 br label %if.end7
33
34 if.end7:
35 %mul = mul nsw i32 %ret.0, %ret.0
36 ret i32 %mul
37 }
38 ; USE: Edge 0: 1-->3 c W=8000 Count=0
39 ; USE: Edge 1: 3-->5 c W=8000 Count=20
40 ; USE: Edge 2: 0-->1 W=16 Count=21
41 ; USE: Edge 3: 5-->0 * W=16 Count=20
42 ; USE: Edge 4: 1-->2 W=8 Count=21
43 ; USE: Edge 5: 2-->3 * W=8 Count=21
44 ; USE: Edge 6: 3-->4 W=8 Count=0
45 ; USE: Edge 7: 4-->5 * W=8 Count=0