This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Use region for each loop in native path.
ClosedPublic

Authored by fhahn on Apr 3 2022, 1:34 PM.

Details

Summary

This patch updates the VPlan native path to use VPRegionBlocks for all
loops in a loop nest. Up to now, only the outermost loop used a region.

This is a step towards unifying both paths and keep things consistent
between them. It also prepares various code-gen parts for modeling the
pre-header in the inner loop vectorizer (D121624).

Diff Detail

Event Timeline

fhahn created this revision.Apr 3 2022, 1:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2022, 1:34 PM
fhahn requested review of this revision.Apr 3 2022, 1:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2022, 1:34 PM
Herald added a subscriber: vkmr. · View Herald Transcript
fhahn updated this revision to Diff 420129.Apr 4 2022, 3:18 AM

Split off removal of unused utilities to D123017.

fhahn retitled this revision from [VPlan] Use region for each loop in native path, remove VPLoopInfo. to [VPlan] Use region for each loop in native path..Apr 4 2022, 4:03 AM
fhahn edited the summary of this revision. (Show Details)
Ayal added inline comments.Apr 27 2022, 3:27 PM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
8672

nit: can also remove brackets

llvm/lib/Transforms/Vectorize/VPlan.cpp
284

update error message?
Simpler to retain the "if (isa<UnreachableInst>(...)) {" and add an "else if (auto *TermBr = dyn_cast<BranchInst>(...))"?

llvm/lib/Transforms/Vectorize/VPlan.h
40

nit: formatting fix independent of this patch

2645

May as well return to current version(?) doing

if (auto *R = dyn_cast<VPRegionBlock>(getEntry()))
  return R;
2651

ditto

Ayal added inline comments.Apr 27 2022, 3:27 PM
llvm/lib/Transforms/Vectorize/VPlan.cpp
269

Comment still intact?

285

remove brackets

293

} else if {

295

(unrelated to this patch): assert PredVPSuccessors[idx] == this?

299

worth a comment?
In this case PredVPBB is the exit block of a loop region - PredVPSuccessors.size() is zero?

302

error messages? cast instead of dyn_cast?
assert PredVPSuccessors is empty and PredBBTerminator has no successors?
assert PredVPBB == Reg->getExitBasicBlock()?
Reg>>LoopRegion, as Reg may also refer to Register(?)

313

Worth a comment - why have a(n exit) block with recipes if it's execute is skipped?
This is not instead of the continues in RPOT traversal below, right?

321

"NonReplicateRegion" >> "LoopRegion"?

328

ditto

345

Augment explanation of case B above. The case of SingleHPred being a LoopRegion is clear, what is the other case of SingleHPred residing in same LoopRegion enclosing this VPBB?

Need the extra brackets around

SingleHPred->getParent() == GetEnclosingNonReplicateRegion(this) &&
!IsNonReplicateR(SingleHPred)?

?

946

nit: why is setting CFG.PrevBB moved?

948

Explanation why if entry is a VPBB (preheader?) then VectorHeaderBB is merged into its predecessor - VectorPreHeader?

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
77

typo: TheLoop

86

\p HeaderBB should be \p LatchBB in order to skip the backedge when it is a predecessor?

287

Why move?
Comment no longer true - Preheader's predecessors no longer set during RPO traversal?

323

Why move?

341

Why added spaces?

360

Backedge was not connected above?

fhahn updated this revision to Diff 426058.Apr 29 2022, 7:48 AM
fhahn marked 22 inline comments as done.

Rebased and addressed comments, thanks!

fhahn added inline comments.Apr 29 2022, 7:51 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
8672

Should be fixed!

llvm/lib/Transforms/Vectorize/VPlan.cpp
269

This is not relevant any longer, removed!

284

Unfortunately the diff was showing changes that were landed as part of a different review. I applied the suggestions in e66127e69bfa. That applies for all suggestions for changes in VPlan.cpp.

293

Simplified, thanks!

299

Added a comment, thanks!

302

Renamed and added extra assertions, thanks!

313

After re-ordering the patches, this is not needed any longer (originally this patch was placed before introducing any recipes in the exit)

321

This has been simplified in the latest version, now there's just a single IsLoopRegion helper.

345

Should be updated in the latest version

946

Not moved in the latest version.

948

This is also gone in the latest version.

llvm/lib/Transforms/Vectorize/VPlan.h
40

Should be fixed, thanks!

2645

This now just does cast<VPRegionBlock>(getEntry()->getSingleSuccessor())

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
77

I *think* this should be fixed.

86

HeaderBB/LatchBB is gone in the latest version.

287

Why move?

The move was accidental, but the comment is not longer true because the predecessor doesn't have any predecessors.

323

Undone.

341

Should be removed.

360

In the latest version, the backedge is connect earlier and removed here.

fhahn added a comment.May 29 2022, 4:33 AM

Ping :) I think all outstanding comments should have been addressed

Ayal added inline comments.May 29 2022, 3:11 PM
llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
93

Is this change needed?

119

Also comment that if \p BB belongs to a loop (except for preheader - said loop needs to be in the scope of VPlan?), then the new empty VPBB is placed in a corresponding VPRegion - if exists otherwise in a new one.

126

Deserves a separate getOrCreate[EnclosingLoop]Region()?

141

Would be good to add a test with nested loops showing how multiple regions are now being created, whereas until now only the outermost loop was region'd.

274

PreheaderVPBB >> VPlanPreheaderVPBB, to emphasize it's VPlan's outer/entry VPBB, to be returned at the end?

284

Is this change needed?

Move the comment about setting Preheader's predecessors along with setOneSuccessor? BTW, comment probably meant to refer to setting the predecessor(s) of Preheader's successor, as Preheader surely has no predecessors set, moreover during RPO traversal below.

333
  1. >> 2. ?
335

createVPInstructionsForVPBB() is removed because exit BB should not be populated; is the current population simply redundant, and can be removed independent of this patch? Should LoopExitVPBB, not being part of the (the) loop, be replaced by LiveOut VPUsers (surely independent of this patch)?

340–370
  1. >> 3. ?
356

HeaderPred >> PreheaderVPBB?

366

LatchSucc >> ExitVPBB? Where LatchVPBB == ExitingVPBB.

374
  1. >> 4.
388

Unrelated to this patch: setName under LLVM_DEBUG?

390

getVectorLoopRegion()?

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
27–30

Simply

ReversePostOrderTraversal<VPBlockBase *> RPOT(Plan->getEntry());

would do, or is the Wrapper needed for blocksOnly()?
Until now it works w/o the blocksOnly<VPBasicBlock>(), because TopRegion is skipped, and there were no other regions.

So now we do widen instructions in pre-header and (empty) exit/middle blocks having zero predecessors and successors respectively, right?

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
53

(To be renamed ExitingBasicBlock, which has no successors but a CondBit to denote when to exit the loop...)

llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
49

Can explain:

// Check that the region following the preheader is a single basic-block region (loop).
177

ditto, outline to a common function checking for a single basic-block region (loop)?

fhahn updated this revision to Diff 432970.May 30 2022, 12:23 PM
fhahn marked 17 inline comments as done.

Address latest comments, thanks!

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
93

Nope, removed the stray change, thanks!

119

Extended the comment, thanks!

126

Given that is is just used here I'm not sure if it is worth pulling this out. Could be a lambda if you think early exits would help readability?

141

Good point, looks like we are missing a VPlan printing ttest for outer loop vectorization. Added in b7d2b160c3ba

274

Done, thanks!

284

Is this change needed?

It's not needed in the latest version of the patch, changed removed, thanks!

Move the comment about setting Preheader's predecessors along with setOneSuccessor? BTW, comment probably meant to refer to setting the predecessor(s) of Preheader's successor, as Preheader surely has no predecessors set, moreover during RPO traversal below.

Yeah, I'll remove the commit.

333

Numbering updated, thanks!

340–370

Numbering updated, thanks!

356

Fixed, thanks!

366

Done! Also Updated LatchVPBB -> ExitingVPBB, with an assertion that getLoopLatch() == getExitingBlock()

374

Numbering fixed, thanks!

388

Will do separately.

390

updated, thanks!

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
27–30

Simply
ReversePostOrderTraversal<VPBlockBase *> RPOT(Plan->getEntry());

Yes, updated, thanks!

So now we do widen instructions in pre-header and (empty) exit/middle blocks having zero predecessors and successors respectively, right?

They will be empty at the moment so nothing happens at the moment.

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
53

Updated!

llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
49

Added, thanks!

177

Added, thanks!

fhahn updated this revision to Diff 432987.May 30 2022, 2:14 PM

Remove some more dead code (VPBBsToFix is not needed any longer).

Ayal accepted this revision.May 31 2022, 1:53 PM

This looks good to me, ship it!

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
126

Added comment suffices to help readability, thanks!

274

nit: could alternatively use the "The" prefix to denote elements of the topmost/outer loop/region, following TheLoop: ThePreheaderBB, ThePreheaderVPBB, ...

This revision is now accepted and ready to land.May 31 2022, 1:53 PM
This revision was landed with ongoing or failed builds.Jun 1 2022, 2:41 AM
This revision was automatically updated to reflect the committed changes.