[llvm] f9172d3 - [AA] Add helper to update result (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 18 07:48:07 PDT 2020
Author: Nikita Popov
Date: 2020-10-18T16:43:26+02:00
New Revision: f9172d3c7b2af5e5712ea330a06e33e9c1ced051
URL: https://github.com/llvm/llvm-project/commit/f9172d3c7b2af5e5712ea330a06e33e9c1ced051
DIFF: https://github.com/llvm/llvm-project/commit/f9172d3c7b2af5e5712ea330a06e33e9c1ced051.diff
LOG: [AA] Add helper to update result (NFC)
This pattern was repeated a few times, and for some reason always
using insert or try_emplace, even though we know in advance that
we're looking for an existing entry and not trying to create a
new one.
Added:
Modified:
llvm/include/llvm/Analysis/AliasAnalysis.h
llvm/lib/Analysis/BasicAliasAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h
index 1e60dd691549..35ee7f4841ee 100644
--- a/llvm/include/llvm/Analysis/AliasAnalysis.h
+++ b/llvm/include/llvm/Analysis/AliasAnalysis.h
@@ -349,6 +349,12 @@ class AAQueryInfo {
IsCapturedCacheT IsCapturedCache;
AAQueryInfo() : AliasCache(), IsCapturedCache() {}
+
+ AliasResult updateResult(const LocPair &Locs, AliasResult Result) {
+ auto It = AliasCache.find(Locs);
+ assert(It != AliasCache.end() && "Entry must have existed");
+ return It->second = Result;
+ }
};
class BatchAAResults;
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index aac36f3a9637..5baf31ed96e3 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1577,12 +1577,8 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
}
// Reset if speculation failed.
- if (Alias != NoAlias) {
- auto Pair =
- AAQI.AliasCache.insert(std::make_pair(Locs, OrigAliasResult));
- assert(!Pair.second && "Entry must have existed");
- Pair.first->second = OrigAliasResult;
- }
+ if (Alias != NoAlias)
+ AAQI.updateResult(Locs, OrigAliasResult);
return Alias;
}
@@ -1801,12 +1797,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
if (const GEPOperator *GV1 = dyn_cast<GEPOperator>(V1)) {
AliasResult Result =
aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2, AAQI);
- if (Result != MayAlias) {
- auto ItInsPair = AAQI.AliasCache.insert(std::make_pair(Locs, Result));
- assert(!ItInsPair.second && "Entry must have existed");
- ItInsPair.first->second = Result;
- return Result;
- }
+ if (Result != MayAlias)
+ return AAQI.updateResult(Locs, Result);
}
if (isa<PHINode>(V2) && !isa<PHINode>(V1)) {
@@ -1818,11 +1810,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
if (const PHINode *PN = dyn_cast<PHINode>(V1)) {
AliasResult Result =
aliasPHI(PN, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
- if (Result != MayAlias) {
- Pair = AAQI.AliasCache.try_emplace(Locs, Result);
- assert(!Pair.second && "Entry must have existed");
- return Pair.first->second = Result;
- }
+ if (Result != MayAlias)
+ return AAQI.updateResult(Locs, Result);
}
if (isa<SelectInst>(V2) && !isa<SelectInst>(V1)) {
@@ -1834,11 +1823,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
if (const SelectInst *S1 = dyn_cast<SelectInst>(V1)) {
AliasResult Result =
aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
- if (Result != MayAlias) {
- Pair = AAQI.AliasCache.try_emplace(Locs, Result);
- assert(!Pair.second && "Entry must have existed");
- return Pair.first->second = Result;
- }
+ if (Result != MayAlias)
+ return AAQI.updateResult(Locs, Result);
}
// If both pointers are pointing into the same object and one of them
@@ -1846,19 +1832,14 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
if (O1 == O2)
if (V1Size.isPrecise() && V2Size.isPrecise() &&
(isObjectSize(O1, V1Size.getValue(), DL, TLI, NullIsValidLocation) ||
- isObjectSize(O2, V2Size.getValue(), DL, TLI, NullIsValidLocation))) {
- Pair = AAQI.AliasCache.try_emplace(Locs, PartialAlias);
- assert(!Pair.second && "Entry must have existed");
- return Pair.first->second = PartialAlias;
- }
+ isObjectSize(O2, V2Size.getValue(), DL, TLI, NullIsValidLocation)))
+ return AAQI.updateResult(Locs, PartialAlias);
// Recurse back into the best AA results we have, potentially with refined
// memory locations. We have already ensured that BasicAA has a MayAlias
// cache result for these, so any recursion back into BasicAA won't loop.
AliasResult Result = getBestAAResults().alias(Locs.first, Locs.second, AAQI);
- Pair = AAQI.AliasCache.try_emplace(Locs, Result);
- assert(!Pair.second && "Entry must have existed");
- return Pair.first->second = Result;
+ return AAQI.updateResult(Locs, Result);
}
/// Check whether two Values can be considered equivalent.
More information about the llvm-commits
mailing list