This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Consider all recipes in replicate blocks as sink candidates.
ClosedPublic

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

Details

Summary

Update sinkScalarOperands to consider all operands of recipes in
replicate blocks as sink candidates This enables additional sinking
opportunities and is another step towards retiring LLVM IR-based
sinkScalarOperands.

Depends on D139788.

Diff Detail

Event Timeline

fhahn created this revision.Dec 11 2022, 9:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2022, 9:22 AM
fhahn requested review of this revision.Dec 11 2022, 9:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2022, 9:22 AM
Ayal added inline comments.Dec 11 2022, 2:32 PM
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
112–113

Following the documentation iterate over VPBlockUtils::blocksOnly<VPRegionBlock>(Iter)?

llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge.ll
35

The iterative scan up use-def chains stops at GEPs?

fhahn updated this revision to Diff 482643.Dec 13 2022, 3:14 PM
fhahn marked an inline comment as done.

Adjust code to iterate over region blocks, thanks!

fhahn marked an inline comment as done.Dec 13 2022, 3:14 PM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
112–113

Done, thanks!

llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge.ll
35

At the moment only replicate & scalar-steps recipe can be sunk.

Ayal added inline comments.Dec 17 2022, 12:04 PM
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
125

nit: Recipe.getParent() >> VPBB (independent of this patch).

Perhaps a Replicating Region, which represents an "if-then" structured-control-flow hammock, should provide an interface for retrieving its (then) "replicating (basic) block".

llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge.ll
35

Right, but curious why the use-def scan failed to sink vp<[[STEPS]]> used by sunk REPLICATEs of GEPS while scanning all recipes in replicate block succeeded. Is this due to the now iterative nature of applying sinkScalarOperands()?

fhahn abandoned this revision.Dec 31 2022, 8:23 AM
fhahn marked 3 inline comments as done.

This is no longer needed after aa2414729ebb

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
125

nit: Recipe.getParent() >> VPBB (independent of this patch).

Done in 435e220ba6a41afbeaef6019febddc1b89bf4214

Perhaps a Replicating Region, which represents an "if-then" structured-control-flow hammock, should provide an interface for retrieving its (then) "replicating (basic) block".

Sounds like a good follow up!

llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge.ll
35

Ah right! I had another look and the issue was that operands of instructions that do not need sinking aren't added to the worklist. Should be fixed by aa2414729ebb

Ayal added inline comments.Dec 31 2022, 3:12 PM
llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge.ll
35

Hmm, that may have been intentional - to prevent revisiting same candidates multiple times during a scan up use-def chains. But that assumed operands that do not need sinking were sunk in the "current" scan - when activated only once, starting with a single seed per replicate region. Whereas now the first scan starts with a single seed but repeated iterative scans should indeed consider all / more-than-one?

fhahn reclaimed this revision.Jan 10 2023, 2:04 AM
fhahn marked 3 inline comments as done.

Re-open the revision as after discussion this approach seems preferable to aa2414729ebb

llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge.ll
35

As discussed, aa2414729ebb has been reverted and the current patch seems preferable;

Whereas now the first scan starts with a single seed but repeated iterative scans should indeed consider all / more-than-one?

Yes, now sinkScalarOperands may be called for triangles with multiple instructions.

fhahn marked an inline comment as done.Jan 16 2023, 6:07 AM

ping :)

Ayal accepted this revision.Jan 19 2023, 6:14 AM

Looks good to me.
May indicate in the commit message that this addresses the iterative nature of sink scalar operands where it is invoked repeatedly.

This revision is now accepted and ready to land.Jan 19 2023, 6:14 AM
fhahn updated this revision to Diff 491074.Jan 21 2023, 7:03 AM

Thanks, rebase before landing.

This revision was landed with ongoing or failed builds.Jan 21 2023, 9:14 AM
This revision was automatically updated to reflect the committed changes.