diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 7590863853295..5a4dbcad1cdcd 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2237,6 +2237,11 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF, const Value *Ptr = getLoadStorePointerOperand(&Ingredient); assert(!Reverse && "Inconsecutive memory access should not have the order."); + if ((isa(Ingredient) && + !Ctx.TTI.isLegalMaskedGather(Ty, Alignment)) || + (isa(Ingredient) && + !Ctx.TTI.isLegalMaskedScatter(Ty, Alignment))) + return InstructionCost::getInvalid(); return Ctx.TTI.getAddressComputationCost(Ty) + Ctx.TTI.getGatherScatterOpCost(Ingredient.getOpcode(), Ty, Ptr, IsMasked, Alignment, CostKind,