Skip to content

Commit

Permalink
[PGO] Don't cross reference CSFDO profile and non-CSFDO profile
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xur-llvm committed Jul 15, 2022
1 parent 19ac753 commit 4a40fa8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
14 changes: 13 additions & 1 deletion llvm/lib/ProfileData/InstrProfReader.cpp
Expand Up @@ -1034,12 +1034,24 @@ IndexedInstrProfReader::getInstrProfRecord(StringRef FuncName,
if (Err)
return std::move(Err);
// Found it. Look for counters with the right hash.

// A flag to indicate if the records are from the same type
// of profile (i.e cs vs nocs).
bool CSBitMatch = false;

for (const NamedInstrProfRecord &I : Data) {
// Check for a match and fill the vector if there is one.
if (I.Hash == FuncHash)
return std::move(I);
if (NamedInstrProfRecord::hasCSFlagInHash(I.Hash) ==
NamedInstrProfRecord::hasCSFlagInHash(FuncHash)) {
CSBitMatch = true;
}
}
if (CSBitMatch) {
return error(instrprof_error::hash_mismatch);
}
return error(instrprof_error::hash_mismatch);
return error(instrprof_error::unknown_function);
}

Expected<memprof::MemProfRecord>
Expand Down
10 changes: 10 additions & 0 deletions llvm/test/Transforms/PGOProfile/Inputs/cs_vs_nocs.proftext
@@ -0,0 +1,10 @@
# CSIR level Instrumentation Flag
:csir
bar
# Func Hash:
1895182923573755903
# Num Counters:
1
# Counter Values:
100000

13 changes: 13 additions & 0 deletions llvm/test/Transforms/PGOProfile/diag_no_funcprofdata_cs.ll
@@ -0,0 +1,13 @@
; RUN: llvm-profdata merge %S/Inputs/cs_vs_nocs.proftext -o %t.profdata
; RUN: opt < %s -passes=pgo-instr-use -pgo-warn-missing-function=true -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s

; CHECK: warning: {{.+}}: no profile data available for function bar
; CHECK-NOT: warning: {{.+}}: function control flow change detected (hash mismatch)

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i32 @bar() {
entry:
ret i32 0
}

0 comments on commit 4a40fa8

Please sign in to comment.