[llvm] [LoopVectorize] Enable vectorisation of early exit loops with live-outs (PR #120567)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 05:47:15 PST 2025


================
@@ -9093,19 +9112,38 @@ addUsersInExitBlocks(VPlan &Plan,
       if (Op->isLiveIn())
         continue;
 
-      // Currently only live-ins can be used by exit values from blocks not
-      // exiting via the vector latch through to the middle block.
-      if (ExitIRI->getParent()->getSinglePredecessor() != MiddleVPBB)
-        return false;
-
       LLVMContext &Ctx = ExitIRI->getInstruction().getContext();
-      VPValue *Ext = B.createNaryOp(VPInstruction::ExtractFromEnd,
-                                    {Op, Plan.getOrAddLiveIn(ConstantInt::get(
-                                             IntegerType::get(Ctx, 32), 1))});
+      VPValue *Ext;
+      VPBasicBlock *PredVPBB =
+          cast<VPBasicBlock>(ExitIRI->getParent()->getPredecessors()[Idx]);
+      if (PredVPBB != MiddleVPBB) {
+        assert(ExitIRI->getParent()->getNumPredecessors() <= 2);
+
+        // Cache the early exit mask
----------------
david-arm wrote:

Yeah that's right. If we don't store the mask in the VPRegionBlock then we have to calculate it manually and I was hoping to avoid constant recalculation of the same value. I could also just calculate this prior to the loop, but then the work is unnecessary if there aren't any early exits.

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


More information about the llvm-commits mailing list