Skip to content

Commit b7fbb33

Browse files
committed
Directly assume alias query with existing map entry is a MustAlias
1 parent 68f3016 commit b7fbb33

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class AliasSetTracker {
253253

254254
AliasSet &addPointer(MemoryLocation Loc, AliasSet::AccessLattice E);
255255
AliasSet *mergeAliasSetsForPointer(const MemoryLocation &MemLoc,
256-
bool &MustAliasAll);
256+
AliasSet *PtrAS, bool &MustAliasAll);
257257

258258
/// Merge all alias sets into a single set that is considered to alias any
259259
/// pointer.

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,33 @@ void AliasSetTracker::clear() {
214214

215215
/// mergeAliasSetsForPointer - Given a pointer, merge all alias sets that may
216216
/// alias the pointer. Return the unified set, or nullptr if no set that aliases
217-
/// the pointer was found. MustAliasAll is updated to true/false if the pointer
218-
/// is found to MustAlias all the sets it merged.
217+
/// the pointer was found. A known existing alias set for the pointer value of
218+
/// the memory location can be passed in (or nullptr if not available).
219+
/// MustAliasAll is updated to true/false if the pointer is found to MustAlias
220+
/// all the sets it merged.
219221
AliasSet *
220222
AliasSetTracker::mergeAliasSetsForPointer(const MemoryLocation &MemLoc,
221-
bool &MustAliasAll) {
223+
AliasSet *PtrAS, bool &MustAliasAll) {
222224
AliasSet *FoundSet = nullptr;
223225
MustAliasAll = true;
224226
for (AliasSet &AS : llvm::make_early_inc_range(*this)) {
225227
if (AS.Forward)
226228
continue;
227229

228-
AliasResult AR = AS.aliasesPointer(MemLoc, AA);
229-
if (AR == AliasResult::NoAlias)
230-
continue;
231-
232-
if (AR != AliasResult::MustAlias)
233-
MustAliasAll = false;
230+
// An alias set that already contains a memory location with the same
231+
// pointer value is directly assumed to MustAlias; we bypass the AA query in
232+
// this case.
233+
// Note: it is not guaranteed that AA would always provide the same result;
234+
// a known exception are undef pointer values, where alias(undef, undef) is
235+
// NoAlias, while we treat it as MustAlias.
236+
if (&AS != PtrAS) {
237+
AliasResult AR = AS.aliasesPointer(MemLoc, AA);
238+
if (AR == AliasResult::NoAlias)
239+
continue;
240+
241+
if (AR != AliasResult::MustAlias)
242+
MustAliasAll = false;
243+
}
234244

235245
if (!FoundSet) {
236246
// If this is the first alias set ptr can go into, remember it.
@@ -286,18 +296,12 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
286296
// consistent.
287297
// This, of course, means that we will never need a merge here.
288298
AS = AliasAnyAS;
289-
} else if (AliasSet *AliasAS =
290-
mergeAliasSetsForPointer(MemLoc, MustAliasAll)) {
299+
} else if (AliasSet *AliasAS = mergeAliasSetsForPointer(
300+
MemLoc,
301+
MapEntry ? MapEntry->getForwardedTarget(*this) : nullptr,
302+
MustAliasAll)) {
291303
// Add it to the alias set it aliases.
292304
AS = AliasAS;
293-
} else if (MapEntry) {
294-
// Although we have an independent memory location, forgo creating a new
295-
// alias set to retain the implementation invariant that all memory
296-
// locations with the same pointer value are in the same alias set.
297-
// (This is only known to occur for undef pointer values, which AA treats as
298-
// noalias.)
299-
AS = MapEntry->getForwardedTarget(*this);
300-
AS->Alias = AliasSet::SetMayAlias;
301305
} else {
302306
// Otherwise create a new alias set to hold the loaded pointer.
303307
AliasSets.push_back(AS = new AliasSet());

0 commit comments

Comments
 (0)