Skip to content

[DA] Aliasing checks in DA are incorrect #41488

@DMG862

Description

@DMG862
mannequin
Bugzilla Link 42143
Version trunk
OS Linux
CC @fhahn,@hfinkel,@dobbelaj-snps,@LebedevRI,@Meinersbur,@felipepiovezan

Extended Description

The Aliasing checks in DA currently do this:
// Check the original locations (minus size) for noalias, which can happen for
// tbaa, incompatible underlying object locations, etc.
MemoryLocation LocAS(LocA.Ptr, LocationSize::unknown(), LocA.AATags);
MemoryLocation LocBS(LocB.Ptr, LocationSize::unknown(), LocB.AATags);
if (AA->alias(LocAS, LocBS) == NoAlias)
return NoAlias;

// Check the underlying objects are the same
const Value *AObj = GetUnderlyingObject(LocA.Ptr, DL);
const Value *BObj = GetUnderlyingObject(LocB.Ptr, DL);

// If the underlying objects are the same, they must alias
if (AObj == BObj)
return MustAlias;

// We may have hit the recursion limit for underlying objects, or have
// underlying objects where we don't know they will alias.
if (!isIdentifiedObject(AObj) || !isIdentifiedObject(BObj))
return MayAlias;

// Otherwise we know the objects are different and both identified objects so
// must not alias.
return NoAlias;

The alias check is invalid for cases like this, which will return noalias for individual loop iterations, but we care about cross-loop dependencies:
define float @​f() {
entry:
%g = alloca float, align 4
%h = alloca float, align 4
br label %for.body

for.body: ; preds = %for.body, %entry
%p = phi float* [ %g, %entry ], [ %q, %for.body ]
%q = phi float* [ %h, %entry ], [ %p, %for.body ]
%0 = load float, float* %p, align 4
store float undef, float* %q, align 4
%branch_cond = fcmp ugt float %0, 0.0
br i1 %branch_cond, label %for.cond.cleanup, label %for.body

for.cond.cleanup: ; preds = %for.body
ret float undef
}

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillallvm:analysisIncludes value tracking, cost tables and constant folding

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions