[llvm] 4a40fa8 - [PGO] Don't cross reference CSFDO profile and non-CSFDO profile
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 15 14:05:38 PDT 2022
Author: Rong Xu
Date: 2022-07-15T13:57:23-07:00
New Revision: 4a40fa82c07238ea28e041dc0e28b4f2953e509e
URL: https://github.com/llvm/llvm-project/commit/4a40fa82c07238ea28e041dc0e28b4f2953e509e
DIFF: https://github.com/llvm/llvm-project/commit/4a40fa82c07238ea28e041dc0e28b4f2953e509e.diff
LOG: [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
Added:
llvm/test/Transforms/PGOProfile/Inputs/cs_vs_nocs.proftext
llvm/test/Transforms/PGOProfile/diag_no_funcprofdata_cs.ll
Modified:
llvm/lib/ProfileData/InstrProfReader.cpp
Removed:
################################################################################
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<memprof::MemProfRecord>
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
+}
More information about the llvm-commits
mailing list