@@ -1604,18 +1604,22 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
16041604 State.set (this , V);
16051605}
16061606
1607- InstructionCost VPWidenIntrinsicRecipe::computeCost (ElementCount VF,
1608- VPCostContext &Ctx) const {
1607+ // / Compute the cost for the intrinsic \p ID with \p Operands, produced by \p R.
1608+ static InstructionCost getCostForIntrinsics (Intrinsic::ID ID,
1609+ ArrayRef<const VPValue *> Operands,
1610+ const VPRecipeWithIRFlags &R,
1611+ ElementCount VF,
1612+ VPCostContext &Ctx) {
16091613 // Some backends analyze intrinsic arguments to determine cost. Use the
16101614 // underlying value for the operand if it has one. Otherwise try to use the
16111615 // operand of the underlying call instruction, if there is one. Otherwise
16121616 // clear Arguments.
16131617 // TODO: Rework TTI interface to be independent of concrete IR values.
16141618 SmallVector<const Value *> Arguments;
1615- for (const auto &[Idx, Op] : enumerate(operands () )) {
1619+ for (const auto &[Idx, Op] : enumerate(Operands )) {
16161620 auto *V = Op->getUnderlyingValue ();
16171621 if (!V) {
1618- if (auto *UI = dyn_cast_or_null<CallBase>(getUnderlyingValue ())) {
1622+ if (auto *UI = dyn_cast_or_null<CallBase>(R. getUnderlyingValue ())) {
16191623 Arguments.push_back (UI->getArgOperand (Idx));
16201624 continue ;
16211625 }
@@ -1625,21 +1629,31 @@ InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF,
16251629 Arguments.push_back (V);
16261630 }
16271631
1628- Type *RetTy = toVectorizedTy (Ctx.Types .inferScalarType (this ), VF);
1632+ Type *ScalarRetTy = Ctx.Types .inferScalarType (&R);
1633+ Type *RetTy = VF.isVector () ? toVectorizedTy (ScalarRetTy, VF) : ScalarRetTy;
16291634 SmallVector<Type *> ParamTys;
1630- for (unsigned I = 0 ; I != getNumOperands (); ++I)
1631- ParamTys.push_back (
1632- toVectorTy (Ctx.Types .inferScalarType (getOperand (I)), VF));
1635+ for (const VPValue *Op : Operands) {
1636+ ParamTys.push_back (VF.isVector ()
1637+ ? toVectorTy (Ctx.Types .inferScalarType (Op), VF)
1638+ : Ctx.Types .inferScalarType (Op));
1639+ }
16331640
16341641 // TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst.
1635- FastMathFlags FMF = hasFastMathFlags () ? getFastMathFlags () : FastMathFlags ();
1642+ FastMathFlags FMF =
1643+ R.hasFastMathFlags () ? R.getFastMathFlags () : FastMathFlags ();
16361644 IntrinsicCostAttributes CostAttrs (
1637- VectorIntrinsicID , RetTy, Arguments, ParamTys, FMF,
1638- dyn_cast_or_null<IntrinsicInst>(getUnderlyingValue ()),
1645+ ID , RetTy, Arguments, ParamTys, FMF,
1646+ dyn_cast_or_null<IntrinsicInst>(R. getUnderlyingValue ()),
16391647 InstructionCost::getInvalid (), &Ctx.TLI );
16401648 return Ctx.TTI .getIntrinsicInstrCost (CostAttrs, Ctx.CostKind );
16411649}
16421650
1651+ InstructionCost VPWidenIntrinsicRecipe::computeCost (ElementCount VF,
1652+ VPCostContext &Ctx) const {
1653+ SmallVector<const VPValue *> ArgOps (operands ());
1654+ return getCostForIntrinsics (VectorIntrinsicID, ArgOps, *this , VF, Ctx);
1655+ }
1656+
16431657StringRef VPWidenIntrinsicRecipe::getIntrinsicName () const {
16441658 return Intrinsic::getBaseName (VectorIntrinsicID);
16451659}
0 commit comments