[llvm] [LoopVectorize] Enable vectorisation of early exit loops with live-outs (PR #120567)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 07:09:58 PST 2025
================
@@ -501,8 +501,15 @@ void VPBasicBlock::execute(VPTransformState *State) {
UnreachableInst *Terminator = State->Builder.CreateUnreachable();
// Register NewBB in its loop. In innermost loops its the same for all
// BB's.
- if (State->CurrentParentLoop)
- State->CurrentParentLoop->addBasicBlockToLoop(NewBB, *State->LI);
+ Loop *ParentLoop = State->CurrentParentLoop;
----------------
david-arm wrote:
It's possible, although you'll still end up with similar looking code in VPlan::execute where we execute the blocks:
```
for (VPBlockBase *Block : RPOT)
Block->execute(State);
```
It's worth bearing in mind that in VPRegionBlock::execute we also set the ParentLoop:
```
if (!isReplicator()) {
// Create and register the new vector loop.
Loop *PrevLoop = State->CurrentParentLoop;
State->CurrentParentLoop = State->LI->AllocateLoop();
```
and VPRegionBlock is included in that list. So depending upon how the blocks are traversed you may need to cache the previous value each time, i.e. something like:
```
for (VPBlockBase *Block : RPOT) {
Loop *OldParentLoop = State->ParentLoop;
if (Block->getSingleSuccessor() && isExitBlock(Block->getSingleSuccessor()))
State->ParentLoop = ... parent for exit ...
Block->execute(State);
State->ParentLoop = OldParentLoop;
}
```
I'm honestly not sure if that's any better? The only way to do this neatly I think is if you deal with the VP blocks with a single successor exit block in a different loop, i.e.
```
for (VPBlockBase *Block : RPOT) {
if (!Block->getSingleSuccessor() || !isExitBlock(Block->getSingleSuccessor()))
Block->execute(State);
}
```
```
for (VPBlockBase *Block : RPOT) {
if (Block->getSingleSuccessor() && isExitBlock(Block->getSingleSuccessor())) {
State->ParentLoop = ... exit block parent loop ...
Block->execute(State);
}
}
```
https://github.com/llvm/llvm-project/pull/120567
More information about the llvm-commits
mailing list