[llvm] [LV] - Fix crash in epilogue vectorization when AnyOf reduction has no ComputeReductionResult. (PR #213632)

Pawan Nirpal via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 02:41:08 PDT 2026


================
@@ -7624,14 +7624,19 @@ static SmallVector<Instruction *> preparePlanForEpilogueVectorLoop(
     // TODO: Move setting of resume values to prepareToExecute.
     if (auto *ReductionPhi = dyn_cast<VPReductionPHIRecipe>(&R)) {
       // Find the reduction result by searching users of the phi or its backedge
-      // value.
+      // value, looking through intermediate recipes.
       auto IsReductionResult = [](VPRecipeBase *R) {
         auto *VPI = dyn_cast<VPInstruction>(R);
         return VPI && VPI->getOpcode() == VPInstruction::ComputeReductionResult;
       };
-      auto *RdxResult = cast<VPInstruction>(
-          vputils::findRecipe(ReductionPhi->getBackedgeValue(), IsReductionResult));
-      assert(RdxResult && "expected to find reduction result");
+      auto *RdxResult = dyn_cast_or_null<VPInstruction>(vputils::findRecipe(
+          ReductionPhi->getBackedgeValue(), IsReductionResult));
+      // If the ComputeReductionResult was optimized away (e.g., the exit value
+      // was simplified to the start value), the reduction does not contribute
+      // to the exit value. Skip updating the start value for the epilogue,
+      // keeping it as the identity value.
+      if (!RdxResult)
+        continue;
----------------
pawan-nirpal-031 wrote:

I've added changes for deleting this trivial case dead cycle, I'm not sure if this will generalize well for the shapes/non-trivial dead cycles @lukel97 mentions. But I'm wondering if any downstream cleanup from here should be able to do this and so we might not want to do it here.  

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


More information about the llvm-commits mailing list