Skip to content

Commit 4a40fa8

Browse files
committed
[PGO] Don't cross reference CSFDO profile and non-CSFDO profile
Don't cross reference CSFDO profile and non-CSFDO profile when checking the function hash. Only return hash_mismatch when CS bits match, and return unknown_function otherwise. Differential Revision: https://reviews.llvm.org/D129000
1 parent 19ac753 commit 4a40fa8

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,12 +1034,24 @@ IndexedInstrProfReader::getInstrProfRecord(StringRef FuncName,
10341034
if (Err)
10351035
return std::move(Err);
10361036
// Found it. Look for counters with the right hash.
1037+
1038+
// A flag to indicate if the records are from the same type
1039+
// of profile (i.e cs vs nocs).
1040+
bool CSBitMatch = false;
1041+
10371042
for (const NamedInstrProfRecord &I : Data) {
10381043
// Check for a match and fill the vector if there is one.
10391044
if (I.Hash == FuncHash)
10401045
return std::move(I);
1046+
if (NamedInstrProfRecord::hasCSFlagInHash(I.Hash) ==
1047+
NamedInstrProfRecord::hasCSFlagInHash(FuncHash)) {
1048+
CSBitMatch = true;
1049+
}
1050+
}
1051+
if (CSBitMatch) {
1052+
return error(instrprof_error::hash_mismatch);
10411053
}
1042-
return error(instrprof_error::hash_mismatch);
1054+
return error(instrprof_error::unknown_function);
10431055
}
10441056

10451057
Expected<memprof::MemProfRecord>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# CSIR level Instrumentation Flag
2+
:csir
3+
bar
4+
# Func Hash:
5+
1895182923573755903
6+
# Num Counters:
7+
1
8+
# Counter Values:
9+
100000
10+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llvm-profdata merge %S/Inputs/cs_vs_nocs.proftext -o %t.profdata
2+
; RUN: opt < %s -passes=pgo-instr-use -pgo-warn-missing-function=true -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
3+
4+
; CHECK: warning: {{.+}}: no profile data available for function bar
5+
; CHECK-NOT: warning: {{.+}}: function control flow change detected (hash mismatch)
6+
7+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
8+
target triple = "x86_64-unknown-linux-gnu"
9+
10+
define i32 @bar() {
11+
entry:
12+
ret i32 0
13+
}

0 commit comments

Comments
 (0)