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
3740–3743

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?

8837

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

8842

nit: redundant empty line?

9020

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–202

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
3740–3743

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

8837

Removed arg, thanks!

8842

code is gone

9020

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–202

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
1561

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
1561

Thanks, I added a comment in the committed version!