diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1050,8 +1050,8 @@ // Add new definitions to the worklist. for (VPValue *operand : CurRec->operands()) - if (VPDef *OpDef = operand->getDef()) - Worklist.push_back(cast(OpDef)); + if (VPRecipeBase *OpDef = operand->getDef()) + Worklist.push_back(OpDef); } }); @@ -1064,13 +1064,12 @@ for (VPRecipeBase &Recipe : *VPBB) { if (auto *WidenRec = dyn_cast(&Recipe)) { Instruction &UnderlyingInstr = WidenRec->getIngredient(); - VPDef *AddrDef = WidenRec->getAddr()->getDef(); + VPRecipeBase *AddrDef = WidenRec->getAddr()->getDef(); if (AddrDef && WidenRec->isConsecutive() && Legal->blockNeedsPredication(UnderlyingInstr.getParent())) - collectPoisonGeneratingInstrsInBackwardSlice( - cast(AddrDef)); + collectPoisonGeneratingInstrsInBackwardSlice(AddrDef); } else if (auto *InterleaveRec = dyn_cast(&Recipe)) { - VPDef *AddrDef = InterleaveRec->getAddr()->getDef(); + VPRecipeBase *AddrDef = InterleaveRec->getAddr()->getDef(); if (AddrDef) { // Check if any member of the interleave group needs predication. const InterleaveGroup *InterGroup = @@ -1085,8 +1084,7 @@ } if (NeedPredication) - collectPoisonGeneratingInstrsInBackwardSlice( - cast(AddrDef)); + collectPoisonGeneratingInstrsInBackwardSlice(AddrDef); } } } @@ -8914,7 +8912,7 @@ Plan->addVPValue(Instr, VPV); // If the re-used value is a recipe, register the recipe for the // instruction, in case the recipe for Instr needs to be recorded. - if (auto *R = dyn_cast_or_null(VPV->getDef())) + if (VPRecipeBase *R = VPV->getDef()) RecipeBuilder.setRecipe(Instr, R); continue; } @@ -9286,7 +9284,7 @@ VPValue *Cond = RecipeBuilder.createBlockInMask(OrigLoop->getHeader(), Plan); VPValue *Red = PhiR->getBackedgeValue(); - assert(cast(Red->getDef())->getParent() != LatchVPBB && + assert(Red->getDef()->getParent() != LatchVPBB && "reduction recipe must be defined before latch"); Builder.createNaryOp(Instruction::Select, {Cond, Red, PhiR}); } diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1175,9 +1175,7 @@ /// Returns the backedge value as a recipe. The backedge value is guaranteed /// to be a recipe. - VPRecipeBase *getBackedgeRecipe() { - return cast(getBackedgeValue()->getDef()); - } + VPRecipeBase *getBackedgeRecipe() { return getBackedgeValue()->getDef(); } }; class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe { @@ -3059,7 +3057,7 @@ // vectorization inside a vector region. if (VPV->isDefinedOutsideVectorRegions()) return true; - VPDef *Def = VPV->getDef(); + VPRecipeBase *Def = VPV->getDef(); assert(Def && "Must have definition for value defined inside vector region"); if (auto Rep = dyn_cast(Def)) return Rep->isUniform(); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -109,6 +109,11 @@ } #endif +VPRecipeBase *VPValue::getDef() { return cast_or_null(Def); } +const VPRecipeBase *VPValue::getDef() const { + return cast_or_null(Def); +} + // Get the top-most entry block of \p Start. This is the entry block of the // containing VPlan. This function is templated to support both const and non-const blocks template static T *getPlanEntry(T *Start) { @@ -1104,6 +1109,6 @@ VPBasicBlock *Preheader = Plan.getEntry()->getEntryBasicBlock(); VPValue *Step = new VPExpandSCEVRecipe(Expr, SE); - Preheader->appendRecipe(cast(Step->getDef())); + Preheader->appendRecipe(Step->getDef()); return Step; } diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h --- a/llvm/lib/Transforms/Vectorize/VPlanValue.h +++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h @@ -182,8 +182,8 @@ void replaceAllUsesWith(VPValue *New); - VPDef *getDef() { return Def; } - const VPDef *getDef() const { return Def; } + VPRecipeBase *getDef(); + const VPRecipeBase *getDef() const; /// Returns the underlying IR value, if this VPValue is defined outside the /// scope of VPlan. Returns nullptr if the VPValue is defined by a VPDef @@ -328,7 +328,7 @@ /// Add \p V as a defined value by this VPDef. void addDefinedValue(VPValue *V) { - assert(V->getDef() == this && + assert(V->Def == this && "can only add VPValue already linked with this VPDef"); DefinedValues.push_back(V); } @@ -336,8 +336,7 @@ /// Remove \p V from the values defined by this VPDef. \p V must be a defined /// value of this VPDef. void removeDefinedValue(VPValue *V) { - assert(V->getDef() == this && - "can only remove VPValue linked with this VPDef"); + assert(V->Def == this && "can only remove VPValue linked with this VPDef"); assert(is_contained(DefinedValues, V) && "VPValue to remove must be in DefinedValues"); erase_value(DefinedValues, V);