This is an archive of the discontinued LLVM Phabricator instance.

[LV] Split off code to create initial VPlan (NFC).
ClosedPublic

Authored by fhahn on Jul 6 2023, 12:27 PM.

Details

Summary

Split up tryToBuildVPlanWithVPRecipes into intial plan creation and
optimizations.

Depends on D154640.

Diff Detail

Event Timeline

fhahn created this revision.Jul 6 2023, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2023, 12:27 PM
fhahn requested review of this revision.Jul 6 2023, 12:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2023, 12:27 PM
Herald added subscribers: wangpc, vkmr. · View Herald Transcript
Ayal added a comment.Jul 12 2023, 11:32 AM

Thanks for following-up with refactoring the excessive tryToBuildVPlanWithVPRecipes!
This raises several thoughts...

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9055

An alternative refactoring may be to outline the second "Now optimize the initial VPlan" part, rather than the first "build Initial VPlan" part. This could be done perhaps by introducing a new VPlanTransforms::process(VPlan) method which manages all passes, similar to the meta-pass createAndOptimizeReplicateRegions().

9073

Should this mark the completion of an initial VPlan, which now fully represents its scope and can be transformed w/o referring to original IR based relations?

9077

This is currently the only transformation which may bail out of building a VPlan entirely. Marking the optional completion of an initial VPlan here would enable separating it from transformations that only improve it w/o bailing out, as in having the caller do:

if (auto Plan = tryToBuildInitialVPlanWithVPRecipes(SubRange, DeadInstructions)) {
  transformVPlanWithRecipes(*Plan); // Or directly VPlanTransforms::process(*Plan);
  VPlans.push_back(std::move(*Plan));
}

which clearly indicates that DeadInstructions and SubRange are not used nor modified by the latter transforming phase.

9079–9080

Note that creating replicate regions is currently the only (meta) pass that is mandatory. It may be useful to have a minimal "-O0" path consisting of vital transforms only, which checks the functional correctness of the outcome.

fhahn updated this revision to Diff 546997.Aug 3 2023, 2:00 PM

Restructure code as suggested by first only splitting off pure VPlan-to-VPlan optimizations.

fhahn marked 4 inline comments as done.Aug 3 2023, 2:02 PM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9055

Adjusted, thanks!

9073

Sounds good as a start, updated!

9077

Adjusted, thanks!

9079–9080

This might be good in the future, not sure how we best model the options (would also be good to allow running individual optimizations)

Ayal accepted this revision.Aug 4 2023, 2:52 AM

This looks good to me, thanks! Adding a couple of final nits.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9080

nit: is replacing return std::move(Plan) here with return Plan possible independent of all other changes?

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

Note: this search works around setting FindMyCast directly by retrieving it from Value2VPValue[IRCast], because the latter mapping should be avoided at this time. Perhaps Casts should be converted into CastRecipes and recorded in IV recipe after the latter is built and before Value2VPValue is abandoned.

792

nit: do the local calls above need the VPlanTransforms:: prefix?

This revision is now accepted and ready to land.Aug 4 2023, 2:52 AM
fhahn updated this revision to Diff 547157.Aug 4 2023, 4:01 AM
fhahn marked 6 inline comments as done.

Address cleanups, thanks! I am planning to land this soon.

fhahn added inline comments.Aug 4 2023, 5:07 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9080

Yep, split off in 39cf2104507a

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

Removed the prefix, thanks!

This revision was landed with ongoing or failed builds.Aug 4 2023, 5:21 AM
This revision was automatically updated to reflect the committed changes.