llvm.org GIT mirror llvm / c2c97e6
[PGO] Better handling of profile hash mismatch We currently assume profile hash conflicts will be caught by an upfront check and we assert for the cases that escape the check. The assumption is not always true as there are chances of conflict. This patch prints a warning and skips annotating the function for the escaped cases,. Differential Revision: https://reviews.llvm.org/D60154 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358225 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 5 months ago
3 changed file(s) with 127 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
10051005 // Is to use the context sensitive profile.
10061006 bool IsCS;
10071007
1008 // Find the Instrumented BB and set the value.
1009 void setInstrumentedCounts(const std::vector &CountFromProfile);
1008 // Find the Instrumented BB and set the value. Return false on error.
1009 bool setInstrumentedCounts(const std::vector &CountFromProfile);
10101010
10111011 // Set the edge counter value for the unknown edge -- there should be only
10121012 // one unknown edge.
10351035 } // end anonymous namespace
10361036
10371037 // Visit all the edges and assign the count value for the instrumented
1038 // edges and the BB.
1039 void PGOUseFunc::setInstrumentedCounts(
1038 // edges and the BB. Return false on error.
1039 bool PGOUseFunc::setInstrumentedCounts(
10401040 const std::vector &CountFromProfile) {
1041 assert(FuncInfo.getNumCounters() == CountFromProfile.size());
1041 // The number of counters here should match the number of counters
1042 // in profile. Return if they mismatch.
1043 if (FuncInfo.getNumCounters() != CountFromProfile.size()) {
1044 return false;
1045 }
10421046 // Use a worklist as we will update the vector during the iteration.
10431047 std::vector WorkList;
10441048 for (auto &E : FuncInfo.MST.AllEdges)
10701074 }
10711075 ProfileCountSize = CountFromProfile.size();
10721076 CountPosition = I;
1077 return true;
10731078 }
10741079
10751080 // Set the count value for the unknown edge. There should be one and only one
11451150 getBBInfo(nullptr).UnknownCountOutEdge = 2;
11461151 getBBInfo(nullptr).UnknownCountInEdge = 2;
11471152
1148 setInstrumentedCounts(CountFromProfile);
1153 if (!setInstrumentedCounts(CountFromProfile)) {
1154 LLVM_DEBUG(
1155 dbgs() << "Inconsistent number of counts, skipping this function");
1156 Ctx.diagnose(DiagnosticInfoPGOProfile(
1157 M->getName().data(),
1158 Twine("Inconsistent number of counts in ") + F.getName().str()
1159 + Twine(": the profile may be stale or there is a function name collision."),
1160 DS_Warning));
1161 return false;
1162 }
11491163 ProgramMaxCount = PGOReader->getMaximumFunctionCount(IsCS);
11501164 return true;
11511165 }
0 # IR level Instrumentation Flag
1 :ir
2 foo
3 # Func Hash:
4 12884901887
5 # Num Counters:
6 1
7 # Counter Values:
8 1
9
0 ; RUN: llvm-profdata merge %S/Inputs/select_hash_conflict.proftext -o %t.profdata
1 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -pgo-instr-select=true -S | FileCheck %s
2 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -pgo-instr-select=true -S | FileCheck %s
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 @a = common dso_local local_unnamed_addr global [16 x i32] zeroinitializer, align 16
8 @c0 = common dso_local local_unnamed_addr global i8 0, align 1
9 @c1 = common dso_local local_unnamed_addr global i8 0, align 1
10 @c2 = common dso_local local_unnamed_addr global i8 0, align 1
11 @c3 = common dso_local local_unnamed_addr global i8 0, align 1
12 @c4 = common dso_local local_unnamed_addr global i8 0, align 1
13 @c5 = common dso_local local_unnamed_addr global i8 0, align 1
14 @c6 = common dso_local local_unnamed_addr global i8 0, align 1
15 @c7 = common dso_local local_unnamed_addr global i8 0, align 1
16 @c8 = common dso_local local_unnamed_addr global i8 0, align 1
17 @c9 = common dso_local local_unnamed_addr global i8 0, align 1
18 @c10 = common dso_local local_unnamed_addr global i8 0, align 1
19 @c11 = common dso_local local_unnamed_addr global i8 0, align 1
20 @c12 = common dso_local local_unnamed_addr global i8 0, align 1
21 @c13 = common dso_local local_unnamed_addr global i8 0, align 1
22 @c14 = common dso_local local_unnamed_addr global i8 0, align 1
23 @c15 = common dso_local local_unnamed_addr global i8 0, align 1
24
25 define i32 @foo(i32 %n) {
26 entry:
27 %0 = load i8, i8* @c0, align 1
28 %tobool = icmp eq i8 %0, 0
29 %cond = select i1 %tobool, i32 2, i32 1
30 store i32 %cond, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 0), align 16
31 %1 = load i8, i8* @c1, align 1
32 %tobool2 = icmp eq i8 %1, 0
33 %cond3 = select i1 %tobool2, i32 2, i32 1
34 store i32 %cond3, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 1), align 4
35 %2 = load i8, i8* @c2, align 1
36 %tobool5 = icmp eq i8 %2, 0
37 %cond6 = select i1 %tobool5, i32 2, i32 1
38 store i32 %cond6, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 2), align 8
39 %3 = load i8, i8* @c3, align 1
40 %tobool8 = icmp eq i8 %3, 0
41 %cond9 = select i1 %tobool8, i32 2, i32 1
42 store i32 %cond9, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 3), align 4
43 %4 = load i8, i8* @c4, align 1
44 %tobool11 = icmp eq i8 %4, 0
45 %cond12 = select i1 %tobool11, i32 2, i32 1
46 store i32 %cond12, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 4), align 16
47 %5 = load i8, i8* @c5, align 1
48 %tobool14 = icmp eq i8 %5, 0
49 %cond15 = select i1 %tobool14, i32 2, i32 1
50 store i32 %cond15, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 5), align 4
51 %6 = load i8, i8* @c6, align 1
52 %tobool17 = icmp eq i8 %6, 0
53 %cond18 = select i1 %tobool17, i32 2, i32 1
54 store i32 %cond18, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 6), align 8
55 %7 = load i8, i8* @c7, align 1
56 %tobool20 = icmp eq i8 %7, 0
57 %cond21 = select i1 %tobool20, i32 2, i32 1
58 store i32 %cond21, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 7), align 4
59 %8 = load i8, i8* @c8, align 1
60 %tobool23 = icmp eq i8 %8, 0
61 %cond24 = select i1 %tobool23, i32 2, i32 1
62 store i32 %cond24, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 8), align 16
63 %9 = load i8, i8* @c9, align 1
64 %tobool26 = icmp eq i8 %9, 0
65 %cond27 = select i1 %tobool26, i32 2, i32 1
66 store i32 %cond27, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 9), align 4
67 %10 = load i8, i8* @c10, align 1
68 %tobool29 = icmp eq i8 %10, 0
69 %cond30 = select i1 %tobool29, i32 2, i32 1
70 store i32 %cond30, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 10), align 8
71 %11 = load i8, i8* @c11, align 1
72 %tobool32 = icmp eq i8 %11, 0
73 %cond33 = select i1 %tobool32, i32 2, i32 1
74 store i32 %cond33, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 11), align 4
75 %12 = load i8, i8* @c12, align 1
76 %tobool35 = icmp eq i8 %12, 0
77 %cond36 = select i1 %tobool35, i32 2, i32 1
78 store i32 %cond36, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 12), align 16
79 %13 = load i8, i8* @c13, align 1
80 %tobool38 = icmp eq i8 %13, 0
81 %cond39 = select i1 %tobool38, i32 2, i32 1
82 store i32 %cond39, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 13), align 4
83 %14 = load i8, i8* @c14, align 1
84 %tobool41 = icmp eq i8 %14, 0
85 %cond42 = select i1 %tobool41, i32 2, i32 1
86 store i32 %cond42, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 14), align 8
87 %15 = load i8, i8* @c15, align 1
88 %tobool44 = icmp eq i8 %15, 0
89 %cond45 = select i1 %tobool44, i32 2, i32 1
90 store i32 %cond45, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @a, i64 0, i64 15), align 4
91 ret i32 %n
92 }
93 ; CHECK-LABEL: define i32 @foo(i32 %n)
94 ; We should skip the profile.
95 ; CHECK-NOT: %{{.*}} = select i1 %{{.*}}, i32 2, i32 1, !prof
96