This is an archive of the discontinued LLVM Phabricator instance.

[LV] Sink scalar operands and merge regions repeatedly.
ClosedPublic

Authored by fhahn on Dec 11 2022, 9:04 AM.

Details

Summary

Merging regions can enable new sinking opportunities (e.g. if users of a
scalar value are moved from different VPBBs into the same VPBB). Sinking
in turn can also enable new merging opportunities (e.g. if a recipe
between to merge-able regions is moved.

To enable more sinking opportunities, repeat sinking & merging if
regions could be merged.

Also fix mergeReplicateRegions to return the correct Changed status.

Diff Detail

Event Timeline

fhahn created this revision.Dec 11 2022, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2022, 9:04 AM
fhahn requested review of this revision.Dec 11 2022, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2022, 9:04 AM
Ayal accepted this revision.Dec 11 2022, 2:40 PM

Nice catch, ship it!

Would be nice to add a test that exercises three iterations of this while loop...

This revision is now accepted and ready to land.Dec 11 2022, 2:40 PM
fhahn updated this revision to Diff 482414.Dec 13 2022, 2:49 AM

Nice catch, ship it!

Would be nice to add a test that exercises three iterations of this while loop...

While adding such a test I found a case where left-over empty blocks between regions prevent further merging. I put up D139927 to clean up redundant blocks and updated this patch to use it as well to simplify a case that needs 3 iterations.

This revision was landed with ongoing or failed builds.Dec 27 2022, 10:10 AM
This revision was automatically updated to reflect the committed changes.
Ayal added inline comments.Dec 27 2022, 12:59 PM
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
226

Post-commit comments:

TODO: merging replicate regions can be simplified similar to merging basic-blocks below, by (renaming it mergeReplicateRegionsIntoSuccessors? and) collecting all Region1's in a Worklist and then traverse it to handle each Region1 including deleting it.

nit: would be good to record the test exercising three iterations of this while loop.

fhahn marked an inline comment as done.Jan 1 2023, 11:53 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
226

TODO: merging replicate regions can be simplified similar to merging basic-blocks below, by (renaming it mergeReplicateRegionsIntoSuccessors? and) collecting all Region1's in a Worklist and then traverse it to handle each Region1 including deleting it.

Thanks, this should be addressed in 89718815c669.

nit: would be good to record the test exercising three iterations of this while loop.

The test should be sink_replicate_region_after_replicate_region after extension in 3d3634e8bd1f5ce543453352b6ec2ae6f29be95e