Skip to content

Commit 820f3c9

Browse files
committed
format & handle cases where cache size is 1
1 parent d6e4042 commit 820f3c9

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

llvm/lib/Analysis/MemoryDependenceAnalysis.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include <cassert>
5252
#include <iterator>
5353
#include <utility>
54-
#include <cmath>
5554

5655
using namespace llvm;
5756

@@ -84,9 +83,6 @@ static cl::opt<unsigned>
8483
// Limit on the number of memdep results to process.
8584
static const unsigned int NumResultsLimit = 100;
8685

87-
// for quickly calculating log
88-
const float ln2 = 0.69314718f;
89-
9086
/// This is a helper function that removes Val from 'Inst's set in ReverseMap.
9187
///
9288
/// If the set becomes empty, remove Inst's entry.
@@ -995,19 +991,19 @@ MemDepResult MemoryDependenceResults::getNonLocalInfoForBlock(
995991
static void
996992
SortNonLocalDepInfoCache(MemoryDependenceResults::NonLocalDepInfo &Cache,
997993
unsigned NumSortedEntries) {
998-
994+
if (Cache.size() == 1)
995+
return;
999996
auto s = Cache.size() - NumSortedEntries;
1000-
if (s < log2(Cache.size()) * ln2) {
1001-
while (s>0) {
997+
if (s < Log2_32(Cache.size()) * llvm::numbers::ln2) {
998+
while (s > 0) {
1002999
NonLocalDepEntry Val = Cache.back();
10031000
Cache.pop_back();
10041001
MemoryDependenceResults::NonLocalDepInfo::iterator Entry =
1005-
std::upper_bound(Cache.begin(), Cache.end() - 1, Val);
1002+
llvm::upper_bound(Cache, Val);
10061003
Cache.insert(Entry, Val);
10071004
s--;
10081005
}
1009-
}
1010-
else {
1006+
} else {
10111007
llvm::sort(Cache);
10121008
}
10131009
}

0 commit comments

Comments
 (0)