This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Don't add live-outs if scalar epilogue is required.
ClosedPublic

Authored by fhahn on Apr 3 2023, 1:53 PM.

Details

Summary

Instead of clearing live outs when a scalar epilogue is required late,
don't add live outs during VPlan construction if a scalar epilogue is
required.

This enables more VPlan-based DCE (if the live out would be the only
user in the plan) and is a step towards removing an access of the cost
model in fixedVectorizedLoop (which is after VPlan execution).

Depends on D147468.

Diff Detail

Event Timeline

fhahn created this revision.Apr 3 2023, 1:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 1:53 PM
fhahn requested review of this revision.Apr 3 2023, 1:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 1:53 PM
Ayal added inline comments.Apr 8 2023, 5:49 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
3723

nit: retain explanation for the emptied else?

TODO: better understand from VPlan if any external (live-out?) users of IVs need to be fixed up, than to ask Cost?

8806

Passing a parameter only to early-exit; better guard the call instead?

8811

nit: redundant empty line?

8997

How about delegating to CM the check if a Range requires a scalar epilog or not:

bool RequiresScalarEpilogue = CM.requiresScalarEpilogue(Range);
if (!RequiresScalarEpilogue) // No users to add when scalar epiloque must be reached. 
  addUsersInExitBlock(HeaderVPBB, MiddleVPBB, OrigLoop, *Plan);

?

llvm/test/Transforms/LoopVectorize/loop-form.ll
201

Load eliminated from vectorized loop body (only), because we now recognize it is useless?

fhahn updated this revision to Diff 511902.Apr 8 2023, 10:00 AM

Address latest comments, thanks!

fhahn marked 5 inline comments as done.Apr 8 2023, 10:04 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
3723

Retained the comment and added the TODO. For fixed order recurrences, I already put up D147472 to do so

8806

Removed arg, thanks!

8811

code is gone

8997

Moved the code to the cost model and also retained the comment for the case scalar epilogue is required.

llvm/test/Transforms/LoopVectorize/loop-form.ll
201

Yes, load is not needed as it is not used inside the vector loop and the scalar epilogue will take care of the value used outside the loop. Not adding VPLiveOuts allows the load to be removed.

Ayal accepted this revision.Apr 8 2023, 10:49 AM

LGTM!

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

Worth documenting?

This revision is now accepted and ready to land.Apr 8 2023, 10:49 AM
This revision was automatically updated to reflect the committed changes.
fhahn marked 5 inline comments as done.
fhahn marked an inline comment as done.Apr 9 2023, 1:19 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
1562

Thanks, I added a comment in the committed version!