Skip to content

Conversation

@shashforge
Copy link
Contributor

VPValue::getDefiningRecipe() can return the ilist sentinel for live-in
values. Dereferencing that sentinel trips the “dyn_cast on a non-existent
value” assertion (PR #148389).

  • Collapse sentinel → nullptr with a small helper.
  • Replace plain isa/dyn_cast with isa_and_present / dyn_cast_if_present.
  • Keep old behaviour for non-sentinel recipes, so the chosen VF doesn’t change.

Added lit test Transforms/LoopVectorize/pr148389-sentinel.ll.

Fixes: #148389

@github-actions
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index fc918c669..5f4fc4c32 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -301,11 +301,11 @@ VPPartialReductionRecipe::computeCost(ElementCount VF,
   // -----------------------------------------------------------------------
   auto safe = [](VPRecipeBase *R) -> VPRecipeBase * {
     return isa_and_present<VPRecipeBase>(R) ? R : nullptr;
-   };
+  };
 
   std::optional<unsigned> Opcode;
-  VPValue       *Op  = getOperand(0);
-  VPRecipeBase  *OpR = safe(Op->getDefiningRecipe());
+  VPValue *Op = getOperand(0);
+  VPRecipeBase *OpR = safe(Op->getDefiningRecipe());
 
   // If the partial reduction is predicated, a select will be operand 0
   using namespace llvm::VPlanPatternMatch;

@shashforge shashforge closed this Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LV] dyn_cast on a non-existent value

1 participant