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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 12:59:54 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;
----------------
fhahn wrote:

can we instead delete the dead cycle? skipping here seems dangerous given we do not check if the value is actually dead

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


More information about the llvm-commits mailing list