[PATCH] D59151: [BasicAA] Reduce no of map seaches [NFCI].

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 8 16:59:14 PST 2019


chandlerc added inline comments.


================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1588-1592
+      auto CacheIt = AliasCache.find(Locs);
+      assert((CacheIt != AliasCache.end()) &&
              "There must exist an entry for the phi node");
-      AliasResult OrigAliasResult = AliasCache[Locs];
-      AliasCache[Locs] = NoAlias;
+      AliasResult OrigAliasResult = CacheIt->second;
+      CacheIt->second = NoAlias;
----------------
While it's a bit awkward, I'd create a scope here because re-using `CacheIt` will be so tempting and is wrong.

```
AliasResult OrigAliasResult;
{
  // Limited lifetime iterator as we can't re-use it once we begin processing.
  auto CacheIt = AliasCache.find(Locs);
  ...
}
```


================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1606-1608
+        auto Pair = AliasCache.insert(std::make_pair(Locs, OrigAliasResult));
+        assert(!Pair.second && "Entry must have existed");
+        Pair.first->second = OrigAliasResult;
----------------
Here and below, the original code does the same number of lookups and seems more clear?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59151/new/

https://reviews.llvm.org/D59151





More information about the llvm-commits mailing list