[llvm] [VPlan] Dispatch to multiple exit blocks via middle blocks. (PR #112138)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 07:23:38 PST 2024


================
@@ -1375,6 +1375,10 @@ bool LoopVectorizationLegality::isFixedOrderRecurrence(
 }
 
 bool LoopVectorizationLegality::blockNeedsPredication(BasicBlock *BB) const {
+  // When vectorizing early exits, create predicates for all blocks, except the
+  // header.
+  if (hasUncountableEarlyExit() && BB != TheLoop->getHeader())
----------------
david-arm wrote:

Is this perhaps too conservative? There is no need yet to predicate blocks leading up to and including the first uncountable exit (see my branch https://github.com/david-arm/llvm-project/tree/ee_autovec2) because the legality code that I introduced in PR #107004 only supports a single uncountable exit that must be the direct predecessor of the latch, and we also only permit instructions that are safe to speculatively execute in the loop. In https://github.com/llvm/llvm-project/commit/b27a332babde3fec55756d72bd5ed8fbe9c1194c I did this by comparing against the latch

```
  if (hasUncountableEarlyExit() && BB == TheLoop->getLoopLatch())
    return true;
```

I'm not saying this is perfect though! Ideally we'd check to see if the block post-dominates (is that the correct terminology?) the first early exiting block or something like that. However, given that PR #88385 was only intended for the simplest of early exit loops I'm not sure if there is a need to over-complicate the logic at the moment.


https://github.com/llvm/llvm-project/pull/112138


More information about the llvm-commits mailing list