This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Update vector latch terminator edge to exit block after execution.
ClosedPublic

Authored by fhahn on May 30 2022, 2:31 PM.

Details

Summary

Instead of setting the successor to the exit using CFG.ExitBB, set it to
nullptr initially. The successor to the exit block is later set either
through createEmptyBasicBlock or after VPlan execution (because at the
moment, no block is created by VPlan for the exit block, the existing
one is reused).

This also enables BranchOnCond to be used as terminator for the exiting
block of the topmost vector region.

Depends on D126618.

Diff Detail

Event Timeline

fhahn created this revision.May 30 2022, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 2:31 PM
fhahn requested review of this revision.May 30 2022, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 2:31 PM
Herald added a subscriber: vkmr. · View Herald Transcript
fhahn updated this revision to Diff 433103.May 31 2022, 8:53 AM

Move code to set branch to ExitBB (aka middle.block) to VPBasicBlock::execute.

Ayal added inline comments.Jun 2 2022, 1:08 AM
llvm/lib/Transforms/Vectorize/VPlan.cpp
265–266

Set here only fallthru successor 0 to NewBB, or only backedge successor 1 to Header?

Intent is to set the backward successor of a conditional (loop) branch when the branch is created, but to set forward successor(s) later when they are created/visited, for all conditional branches? All such successors will not be able to reuse previous BB so must call createEmptyBasicBlock() except for reusing ExitBB.

Note that LoopRegion in this case refers to a nested loop rather than the outer/top/vector loop - createEmptyBasicBlock() call below excludes final Exit VPBB.

290

PredVPBB >> PredVPBlock or ExitingVPBlock? (Expecting BB to mean BasicBlock rather than BlockBase)

292

Add error message?

777–782

(nit: can set IfFalse to null for both above, then setSuccessor(1) to Header if parent isLatch()), as we're setting Successor(0)...

798–799

(nit: is this still needed, or subject to future cleanup?)

802

Here there's only a single destination/successor 0: "destination(s) later when they are" >> "destination later when it is".

Setting IfTrue first to Builder.GetInsertBlock() and then replacing it with nullptr to circumvent an assert of CreateCondBr?

fhahn updated this revision to Diff 433716.Jun 2 2022, 4:51 AM
fhahn marked 6 inline comments as done.

Address latest comments, thanks!

llvm/lib/Transforms/Vectorize/VPlan.cpp
265–266

Intent is to set the backward successor of a conditional (loop) branch when the branch is created, but to set forward successor(s) later when they are created/visited, for all conditional branches?

Exactly! I had another look and the extra code here to handle the exiting block separately is not needed any longer I think with this patch.

It can be handled in the else case above, if we use getHierarchicalSuccessors instead of getSuccessors. This seems simpler and I updated the patch in that respect.

290

Changed to PredVPB, which I think is used elsewhere.

292

Done, also switched to using getSingleSuccessor

777–782

Sounds great, I'll update D126618 accordingly.

798–799

It's not needed any longer, removed in 4f1c86e3d5ef, thanks!

802

Here there's only a single destination/successor 0: "destination(s) later when they are" >> "destination later when it is".

Updated! I also updated the comment to mention backward dest = header, forward dest = exit/middle block.

Setting IfTrue first to Builder.GetInsertBlock() and then replacing it with nullptr to circumvent an assert of CreateCondBr?

Yes, unfortunately the first destination is required to be valid block.

Ayal accepted this revision.Jun 2 2022, 8:30 AM

Ship it!

llvm/lib/Transforms/Vectorize/VPlan.cpp
260–262

nit: assert and use TermBr here?

Can comment that this scan sets each forward successor here when it is created, and excludes backedges. A backward successor is set when the branch is created (as successor 1).

295

Can comment that Exit block of a loop is always set to be successor 0 of the Exiting block.

802

Setting IfTrue first to Builder.GetInsertBlock() and then replacing it with nullptr to circumvent an assert of CreateCondBr?

Yes, unfortunately the first destination is required to be valid block.

Understood. Might be worth a comment.

This revision is now accepted and ready to land.Jun 2 2022, 8:30 AM
This revision was landed with ongoing or failed builds.Jun 4 2022, 1:22 PM
This revision was automatically updated to reflect the committed changes.
fhahn marked 3 inline comments as done.
fhahn added inline comments.Jun 4 2022, 1:23 PM
llvm/lib/Transforms/Vectorize/VPlan.cpp
260–262

Done & comment added, thanks!

295

added the comment, thanks!

802

Extended the comment, thanks!