summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-02-10 06:36:55 +0000
committerXinliang David Li <davidxl@google.com>2016-02-10 06:36:55 +0000
commit86b4b91e352fc01eb8425eb19d5d97656a4b9949 (patch)
tree0153da14e483e3edf02d0d7298588630ff484c41
parentdfe2156f1b6e7a0374a52e9ed8838d452d14438c (diff)
downloadbcm5719-llvm-86b4b91e352fc01eb8425eb19d5d97656a4b9949.tar.gz
bcm5719-llvm-86b4b91e352fc01eb8425eb19d5d97656a4b9949.zip
[PGO] fix prof symbol lookup bug
Patch by Rong Xu The problem is exposed by intra-module indirect call promotion where prof symtab is created from module which does not contain all symbols from the program. With partial symtab, the result needs to be checked more strictly. llvm-svn: 260361
-rw-r--r--llvm/include/llvm/ProfileData/InstrProf.h2
-rw-r--r--llvm/unittests/ProfileData/InstrProfTest.cpp6
2 files changed, 7 insertions, 1 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index c1db9b63404..4a445d230f9 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -379,7 +379,7 @@ StringRef InstrProfSymtab::getFuncName(uint64_t FuncMD5Hash) {
std::lower_bound(MD5NameMap.begin(), MD5NameMap.end(), FuncMD5Hash,
[](const std::pair<uint64_t, std::string> &LHS,
uint64_t RHS) { return LHS.first < RHS; });
- if (Result != MD5NameMap.end())
+ if (Result != MD5NameMap.end() && Result->first == FuncMD5Hash)
return Result->second;
return StringRef();
}
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 3615b0a4359..e2349f4fc57 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -746,6 +746,12 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) {
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar3"));
ASSERT_EQ(StringRef("bar3"), R);
+ // negative tests
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar4"));
+ ASSERT_EQ(StringRef(), R);
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("foo4"));
+ ASSERT_EQ(StringRef(), R);
+
// Now incrementally update the symtab
Symtab.addFuncName("blah_1");
Symtab.addFuncName("blah_2");
OpenPOWER on IntegriCloud