[llvm] [LoopVectorize] Add support for vectorisation of simple early exit loops (PR #88385)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 04:49:54 PDT 2024


================
@@ -3461,16 +3611,28 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
     for (const auto &Entry : Legal->getInductionVars())
       fixupIVUsers(Entry.first, Entry.second,
                    getOrCreateVectorTripCount(VectorLoop->getLoopPreheader()),
-                   IVEndValues[Entry.first], LoopMiddleBlock,
-                   VectorLoop->getHeader(), Plan, State);
+                   IVEndValues[Entry.first], LoopMiddleBlock, Plan, State);
   }
 
   // Fix LCSSA phis not already fixed earlier. Extracts may need to be generated
   // in the exit block, so update the builder.
+  BasicBlock *OrigEarlyExitBB = Legal->hasSpeculativeEarlyExit()
+                                    ? Legal->getSpeculativeEarlyExitBlock()
+                                    : nullptr;
+
   State.Builder.SetInsertPoint(State.CFG.ExitBB,
                                State.CFG.ExitBB->getFirstNonPHIIt());
   for (const auto &KV : Plan.getLiveOuts())
-    KV.second->fixPhi(Plan, State);
+    if (OrigLoop->getUniqueExitBlock() ||
+        KV.second->getPhi()->getParent() != OrigEarlyExitBB)
+      KV.second->fixPhi(Plan, State);
----------------
david-arm wrote:

Good spot! This code was just a hangover from an earlier implementation and it's no longer necessary to have the if guards - we can unconditionally handle all the live-outs.

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


More information about the llvm-commits mailing list