[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
This commit is contained in:
Xinliang David Li 2016-02-10 06:36:55 +00:00
parent dfe2156f1b
commit 86b4b91e35
2 changed files with 7 additions and 1 deletions

View File

@ -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();
}

View File

@ -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");