[llvm] [LV] Fix FindLastIV reduction for epilogue vectorization. (PR #120395)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 11:47:13 PST 2025


================
@@ -3405,15 +3406,13 @@ void VPReductionPHIRecipe::execute(VPTransformState &State) {
     }
   } else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK)) {
     // [I|F]FindLastIV will use a sentinel value to initialize the reduction
-    // phi or the resume value from the main vector loop when vectorizing the
-    // epilogue loop. In the exit block, ComputeReductionResult will generate
-    // checks to verify if the reduction result is the sentinel value. If the
-    // result is the sentinel value, it will be corrected back to the start
-    // value.
+    // phi. In the exit block, ComputeReductionResult will generate checks to
+    // verify if the reduction result is the sentinel value. If the result is
+    // the sentinel value, it will be corrected back to the start value.
     // TODO: The sentinel value is not always necessary. When the start value is
     // a constant, and smaller than the start value of the induction variable,
     // the start value can be directly used to initialize the reduction phi.
-    Iden = StartV;
+    StartV = Iden = RdxDesc.getSentinelValue();
----------------
fhahn wrote:

Would it be possible to do something similar to how we handle the start values for AnyOf in the epilogue vector loop (https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp#L10272), i.e. could we create the new start value for the epilogue loop by checking if the value out of the main vector loop is still the sentinel value or something like that

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


More information about the llvm-commits mailing list