[llvm] [LV] Adjust exit recipe detection to run on early vplan (PR #183318)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 05:53:02 PDT 2026


================
@@ -17,6 +19,60 @@ namespace llvm {
 
 namespace {
 class VPUncountableExitTest : public VPlanTestIRBase {};
+using namespace VPlanPatternMatch;
+
+static void combineExitConditions(VPlan &Plan) {
+  struct EarlyExitInfo {
+    VPBasicBlock *EarlyExitingVPBB;
+    VPIRBasicBlock *EarlyExitVPBB;
+    VPValue *CondToExit;
+  };
+
+  auto *MiddleVPBB = cast<VPBasicBlock>(
+      Plan.getScalarHeader()->getSinglePredecessor()->getPredecessors()[0]);
+  auto *LatchVPBB = cast<VPBasicBlock>(MiddleVPBB->getSinglePredecessor());
+
+  // Find the single early exit: a non-middle predecessor of an exit block.
+  VPBasicBlock *EarlyExitingVPBB = nullptr;
+  VPIRBasicBlock *EarlyExitVPBB = nullptr;
+  for (VPIRBasicBlock *ExitBlock : Plan.getExitBlocks()) {
+    for (VPBlockBase *Pred : ExitBlock->getPredecessors()) {
+      if (Pred != MiddleVPBB) {
+        EarlyExitingVPBB = cast<VPBasicBlock>(Pred);
+        EarlyExitVPBB = ExitBlock;
+      }
+    }
+  }
+  if (!EarlyExitingVPBB)
+    return;
----------------
fhahn wrote:

```suggestion
 assert(EarlyExitingVPBB && "must have an early exit");
```

I think this should only be used for tests with a single early exit, so should be able to assert.

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


More information about the llvm-commits mailing list