This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Add VPlan::hasTailFolded.
Needs ReviewPublic

Authored by fhahn on Aug 3 2023, 2:33 PM.

Details

Reviewers
Ayal
gilr
dmgreen
Summary

This patch adds a helper to check if the tail loop is folded in a
VPlan.

To do so it checks if the VPlan contains a widen canonical IV, a
active-lane-mask-phi, an active-lane-mask or a ICmpULE compare of a
widened canonical induction with the backedge taken count. This should
effectively check if a mask for the header is present, but may be a bit
cumbersome.

Alternatively we could also add a flag to the VPlan.

Depends on D157037.

Diff Detail

Event Timeline

fhahn created this revision.Aug 3 2023, 2:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 2:33 PM
fhahn requested review of this revision.Aug 3 2023, 2:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 2:33 PM
Herald added subscribers: wangpc, vkmr. · View Herald Transcript
Ayal added a comment.Aug 5 2023, 2:30 PM

Alternatively we could also add a flag to the VPlan.

Raising thoughts of other potential alternatives.

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

Could recipes be set initially such that they generate code as needed, rather than (figuring out if tail was folded in order to) fix it here? This seems to require (a) setting FMF of Sel's recipe, (b) optionally rewiring a header phi recipe to Sel's recipe, (c) RAUW of LoopExitInstDef with Sel's recipe, rather than State.reset().

9259

Here, during VPlan construction after header mask was proactively created (depending on D157037), it would be easy/easier to ask RecipeBuilder if the mask cached for the header block is null? Namely, check if Cond below is null.

9271

Set the FMF of the select recipe upon creation here, rather than fixing its generated IR in fixReduction()?