[llvm] [VPlan] Add initial CFG simplification, removing BranchOnCond true. (PR #106748)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 3 06:02:54 PDT 2025


================
@@ -3529,12 +3529,27 @@ class VPlan {
 
   /// Returns the 'middle' block of the plan, that is the block that selects
   /// whether to execute the scalar tail loop or the exit block from the loop
-  /// latch.
-  const VPBasicBlock *getMiddleBlock() const {
-    return cast<VPBasicBlock>(getScalarPreheader()->getPredecessors().front());
-  }
+  /// latch. If there is an early exit from the vector loop, the middle block
+  /// conceptully has the early exit block as third successor, split accross 2
+  /// VPBBs. In that case, the second VPBB selects whether to execute the scalar
+  /// tail loop or the exit bock. If the scalar tail loop or exit block are
+  /// known to always execute, the middle block may branch directly to that
+  /// block. If there is no loop region, the middle block cannot be identified
+  /// and nullptr is returned.
   VPBasicBlock *getMiddleBlock() {
-    return cast<VPBasicBlock>(getScalarPreheader()->getPredecessors().front());
+    VPRegionBlock *LoopRegion = getVectorLoopRegion();
+    if (!LoopRegion)
----------------
ayalz wrote:

nit: do the callers of getMiddleBlock() expect it to return null or assert it does not, or should the callee assert so?

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


More information about the llvm-commits mailing list