This is an archive of the discontinued LLVM Phabricator instance.

[AA] Improve the BasicAA analysis capability
ClosedPublic

Authored by Allen on Sep 9 2022, 3:39 AM.

Details

Summary

According https://discourse.llvm.org/t/memoryssa-does-the-accessedbetween-support-scalable-vector-pointer/65052,
scalable vector support in BasicAA is currently essentially limited,
and should be improved effectively for a constant offset GEP if the scalable index is zero, eg:

getelementptr <vscale x 4 x i32>, ptr %p, i64 0, i64 %i

Diff Detail

Event Timeline

Allen created this revision.Sep 9 2022, 3:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 3:39 AM
Allen requested review of this revision.Sep 9 2022, 3:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 3:39 AM
nikic requested changes to this revision.Sep 9 2022, 3:44 AM

This is not the correct way to address the issue. Support for scalable vectors needs to be added inside DecomposeGEPExpression().

This revision now requires changes to proceed.Sep 9 2022, 3:44 AM
Allen updated this revision to Diff 459322.Sep 10 2022, 10:14 PM
Allen edited the summary of this revision. (Show Details)

refactor in BasicAAResult::DecomposeGEPExpression

This is not the correct way to address the issue. Support for scalable vectors needs to be added inside DecomposeGEPExpression().

apply your comment, thanks @nikic

nikic added inline comments.Sep 11 2022, 12:40 AM
llvm/lib/Analysis/BasicAliasAnalysis.cpp
615

Instead of checking the source element type, this should check whether the getTypeAllocSize fetched below isScalable.

624

nit: Drop else after continue.

llvm/test/Transforms/GVN/vscale.ll
49

Drop TODO.

Allen updated this revision to Diff 459342.Sep 11 2022, 3:12 AM
Allen marked 2 inline comments as done.
Allen added inline comments.
llvm/lib/Analysis/BasicAliasAnalysis.cpp
615

apply your comment, thanks

llvm/test/Transforms/GVN/vscale.ll
49

DONE

nikic added inline comments.Sep 11 2022, 7:01 AM
llvm/lib/Analysis/BasicAliasAnalysis.cpp
615

Please store the getTypeAllocSize() result in a variable and reuse it below. Also, the num operands checks is no longer needed.

629

Here again we should be checking the alloc size, not the source element type. It should be possible to support something like getelementptr <vscale x 4 x i32>, ptr %p, i64 0, i64 %i, where the variable is on a non-scalable index.

Allen updated this revision to Diff 459393.Sep 11 2022, 6:59 PM
Allen marked an inline comment as done.
Allen edited the summary of this revision. (Show Details)

Address the comment, and store the getTypeAllocSize() result in a variable and reuse it, then it extend
getelementptr <vscale x 4 x i32>, ptr %p, i64 0, i64 c --> getelementptr <vscale x 4 x i32>, ptr %p, i64 0, i64 %i

Allen marked 3 inline comments as done.Sep 11 2022, 7:02 PM
Allen added inline comments.
llvm/lib/Analysis/BasicAliasAnalysis.cpp
615

Thanks for detail

629

Yes, good catch, thanks very much

nikic added inline comments.Sep 12 2022, 1:34 AM
llvm/lib/Analysis/BasicAliasAnalysis.cpp
597

Please move this below the StructType check, this call is expensive.

629

Can you please also add a test for this case? Something like using %i and %j = add %i, 1 as indices. should probably work.

Allen updated this revision to Diff 459416.Sep 12 2022, 2:09 AM
Allen marked 2 inline comments as done.

Add a new case redundant_load_elimination_zero_index_1 according comment

nikic accepted this revision.Sep 12 2022, 2:11 AM

LGTM

This revision is now accepted and ready to land.Sep 12 2022, 2:11 AM
Allen marked 2 inline comments as done.Sep 12 2022, 2:11 AM
Allen added inline comments.
llvm/lib/Analysis/BasicAliasAnalysis.cpp
597

Done, thanks

629

Of course, added new case redundant_load_elimination_zero_index_1

This revision was automatically updated to reflect the committed changes.
Allen marked 2 inline comments as done.