diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp index ee8989979a26e..017b09e1c3881 100644 --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -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 diff --git a/llvm/test/Transforms/PGOProfile/Inputs/cs_vs_nocs.proftext b/llvm/test/Transforms/PGOProfile/Inputs/cs_vs_nocs.proftext new file mode 100644 index 0000000000000..73da2f52ddcb6 --- /dev/null +++ b/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 + diff --git a/llvm/test/Transforms/PGOProfile/diag_no_funcprofdata_cs.ll b/llvm/test/Transforms/PGOProfile/diag_no_funcprofdata_cs.ll new file mode 100644 index 0000000000000..1e36c3eee206e --- /dev/null +++ b/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 +}