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

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 09:05:15 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();
----------------
Mel-Chen wrote:

I've given it more thought and realized there might be a more concise approach!
Perhaps we could modify ResumeV as:
```
ResumeV = ResumeV == StartValue ? Sentinel : ResumeV
```
I'll try to make this change and test it tomorrow to see if there are any blind spots we have not notice.

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


More information about the llvm-commits mailing list