This is an archive of the discontinued LLVM Phabricator instance.

[BasicAA] Fix aliasGEP/DecomposeGEPExpression for scalable type.
ClosedPublic

Authored by huihuiz on Apr 9 2020, 2:08 PM.

Details

Summary

Don't attempt to analyze the decomposed GEP for scalable type.
GEP index scale is not compile-time constant for scalable type.
Be conservative, return MayAlias.

Explicitly call TypeSize::getFixedSize() to assert on places where
scalable type doesn't make sense.

Add unit tests to check functionality of -basicaa for scalable type.

This patch is needed for D76944.

Diff Detail

Event Timeline

huihuiz created this revision.Apr 9 2020, 2:08 PM

Current upstream is producing wrong AliasResult for scalable type.

take test.ll , run: opt -basicaa -aa-eval -print-all-alias-modref-info -disable-output test.ll.

Then you will see " MustAlias: i32* %gep1, i32* %gep2 "
gep1,gep2 should be MayAlias, not MustAlias.

define void @gep_bitcast_1(<vscale x 4 x i32>* %p) {
  %gep1 = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* %p, i64 1, i64 0
  %p2 = bitcast <vscale x 4 x i32>* %p to i32*
  %gep2 = getelementptr i32, i32* %p2, i64 4
  ret void
}
efriedma added inline comments.Apr 9 2020, 5:28 PM
llvm/lib/Analysis/BasicAliasAnalysis.cpp
1335

I think this still doesn't completely block off all the relevant cases.

DecomposeGEPExpression is recursive, so there are can be multiple levels of GEPs. The GEP over the scalable vector may not be GEP1; it could be GEP1->getPointerOperand(), or something like that.

huihuiz updated this revision to Diff 256676.Apr 10 2020, 2:55 PM
huihuiz marked an inline comment as done.
huihuiz retitled this revision from [BasicAA][SVE] Fix aliasGEP for scalable type. to [BasicAA] Fix aliasGEP/DecomposeGEPExpression for scalable type..
huihuiz edited the summary of this revision. (Show Details)

Address review comments.

llvm/lib/Analysis/BasicAliasAnalysis.cpp
1335

Good catch, Thanks Eli!

Moving the checks to DecomposeGEPExpression, so we have knowledge of scalable type given multiple levels of GEPs.

Patch updated accordingly, and with more tests in recursive geps.

This revision is now accepted and ready to land.Apr 10 2020, 3:17 PM
This revision was automatically updated to reflect the committed changes.