Skip to content

Commit 45139ab

Browse files
committed
[SLP][NFC]Improve aliasing support in SLP, NFC.
No need to store optional boolean in the map, enough to store boolean directly. Also, we can do preliminary check for instruction and if they are not simple, mark as aliased without storing this result in the map.
1 parent 4d29bda commit 45139ab

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,25 +2982,25 @@ class BoUpSLP {
29822982
/// is invariant in the calling loop.
29832983
bool isAliased(const MemoryLocation &Loc1, Instruction *Inst1,
29842984
Instruction *Inst2) {
2985+
if (!Loc1.Ptr || !isSimple(Inst1) || !isSimple(Inst2))
2986+
return true;
29852987
// First check if the result is already in the cache.
2986-
AliasCacheKey key = std::make_pair(Inst1, Inst2);
2987-
std::optional<bool> &result = AliasCache[key];
2988-
if (result) {
2989-
return *result;
2990-
}
2991-
bool aliased = true;
2992-
if (Loc1.Ptr && isSimple(Inst1))
2993-
aliased = isModOrRefSet(BatchAA.getModRefInfo(Inst2, Loc1));
2988+
AliasCacheKey Key = std::make_pair(Inst1, Inst2);
2989+
auto It = AliasCache.find(Key);
2990+
if (It != AliasCache.end())
2991+
return It->second;
2992+
bool Aliased = isModOrRefSet(BatchAA.getModRefInfo(Inst2, Loc1));
29942993
// Store the result in the cache.
2995-
result = aliased;
2996-
return aliased;
2994+
AliasCache.try_emplace(Key, Aliased);
2995+
AliasCache.try_emplace(std::make_pair(Inst2, Inst1), Aliased);
2996+
return Aliased;
29972997
}
29982998

29992999
using AliasCacheKey = std::pair<Instruction *, Instruction *>;
30003000

30013001
/// Cache for alias results.
30023002
/// TODO: consider moving this to the AliasAnalysis itself.
3003-
DenseMap<AliasCacheKey, std::optional<bool>> AliasCache;
3003+
DenseMap<AliasCacheKey, bool> AliasCache;
30043004

30053005
// Cache for pointerMayBeCaptured calls inside AA. This is preserved
30063006
// globally through SLP because we don't perform any action which

0 commit comments

Comments
 (0)