[llvm] [LoopVectorize] Add support for vectorisation of simple early exit loops (PR #88385)
Graham Hunter via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 06:29:13 PDT 2024
================
@@ -2292,6 +2352,73 @@ void MemoryDepChecker::Dependence::print(
OS.indent(Depth + 2) << *Instrs[Destination] << "\n";
}
+bool LoopAccessInfo::isAnalyzableEarlyExitLoop() {
+ // At least one of the exiting blocks must be the latch.
+ BasicBlock *LatchBB = TheLoop->getLoopLatch();
+ if (!LatchBB)
+ return false;
+
+ SmallVector<BasicBlock *, 8> ExitingBlocks;
+ TheLoop->getExitingBlocks(ExitingBlocks);
+
+ // This is definitely not an early exit loop.
+ if (ExitingBlocks.size() < 2)
+ return false;
+
+ SmallVector<BasicBlock *, 4> ExactExitingBlocks;
+ PSE->getSE()->getExactExitingBlocks(TheLoop, &ExactExitingBlocks);
+
+ // We only support one speculative early exit.
+ if ((ExitingBlocks.size() - ExactExitingBlocks.size()) > 1)
+ return false;
+
+ // There could be multiple exiting blocks with an exact exit-not-taken
+ // count. Find the speculative early exit block, i.e. the one with an
+ // unknown count.
+ BasicBlock *TmpBB = nullptr;
+ for (BasicBlock *BB1 : ExitingBlocks) {
+ bool Found = false;
----------------
huntergr-arm wrote:
I think this can be made a bit simpler, e.g.
```
if (!is_contained(ExactExitingBlocks, BB1)) {
TmpBB = BB1;
break;
}
```
Or you could potentially have a getUncountedExitBlocks() instead.
https://github.com/llvm/llvm-project/pull/88385
More information about the llvm-commits
mailing list