[llvm] [LoopVectorize] Teach LoopVectorizationLegality about more early exits (PR #107004)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 02:13:28 PDT 2024
================
@@ -1445,6 +1445,145 @@ bool LoopVectorizationLegality::canVectorizeLoopNestCFG(
return Result;
}
+bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
+ BasicBlock *LatchBB = TheLoop->getLoopLatch();
+ if (!LatchBB) {
+ reportVectorizationFailure("Loop does not have a latch",
+ "Cannot vectorize early exit loop",
+ "NoLatchEarlyExit", ORE, TheLoop);
+ return false;
+ }
+
+ if (Reductions.size() || FixedOrderRecurrences.size()) {
+ reportVectorizationFailure(
+ "Found reductions or recurrences in early-exit loop",
+ "Cannot vectorize early exit loop with reductions or recurrences",
+ "RecurrencesInEarlyExitLoop", ORE, TheLoop);
+ return false;
+ }
+
+ SmallVector<BasicBlock *, 8> ExitingBlocks;
+ TheLoop->getExitingBlocks(ExitingBlocks);
+
+ // Keep a record of all the exiting blocks.
+ SmallVector<const SCEVPredicate *, 4> Predicates;
+ for (BasicBlock *BB1 : ExitingBlocks) {
+ const SCEV *EC =
+ PSE.getSE()->getPredicatedExitCount(TheLoop, BB1, &Predicates);
+ if (isa<SCEVCouldNotCompute>(EC)) {
+ UncountableExitingBlocks.push_back(BB1);
+
+ SmallVector<BasicBlock *, 2> Succs(successors(BB1));
+ if (Succs.size() != 2) {
+ reportVectorizationFailure(
+ "Early exiting block does not have exactly two successors",
+ "Incorrect number of successors from early exiting block",
+ "EarlyExitTooManySuccessors", ORE, TheLoop);
+ return false;
+ }
+
+ BasicBlock *BB2;
----------------
fhahn wrote:
clearer to name ExitBlock?
https://github.com/llvm/llvm-project/pull/107004
More information about the llvm-commits
mailing list