[llvm] [LV] Vectorize uncountable early exit store loops with combined conditions (PR #205109)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 07:52:50 PDT 2026


================
@@ -2733,6 +2733,27 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
     if (Legal->hasUncountableEarlyExit() && TheLoop->getLoopLatch() != E)
       continue;
     auto *Cmp = dyn_cast<Instruction>(E->getTerminator()->getOperand(0));
+    // TODO: This might occur for a multi-exit readonly loop too?
+    //       Excluded for now in LVL.
+    // TODO: Do we have the main IV available somewhere? this feels a little
+    //       fragile.
+    // If we have an exit condition that is actually two conditions combined
+    // via an or, only add the countable comparison as a uniform value.
+    if (Legal->hasUncountableExitWithSideEffects() &&
+        TheLoop->getLoopLatch() == E) {
+      Value *Uncounted, *Counted, *IV;
+      using namespace llvm::PatternMatch;
+      if (match(Cmp,
+                m_c_LogicalOr(
+                    m_Value(Uncounted, m_Cmp(m_Load(m_Value()), m_Value())),
+                    m_Value(Counted, m_Cmp(m_Add(m_Value(IV), m_Value()),
+                                           m_Value()))))) {
----------------
sdesmalen-arm wrote:

Should this check whether the increment and end values are loop invariant?

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


More information about the llvm-commits mailing list