@@ -990,34 +990,13 @@ InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF,
990990 // clear Arguments.
991991 // TODO: Rework TTI interface to be independent of concrete IR values.
992992 SmallVector<const Value *> Arguments;
993-
994- // In fact, we need to get the VP intrinsics cost from the TTI, but currently
995- // the legacy model, it will always calculate cost of the call Intrinsics, eg:
996- // llvm.ctlz/llvm.smax, so VP Intrinsics should have the same cost as their
997- // non-vp counterpart.
998- // TODO: Use VP intrinsics to calculate the cost, if the following conditions
999- // are met
1000- // 1. We don't need to compare to the legacy cost model
1001- // 2. The cost model of VP is gradually improved in TTI
1002- // 3. VPlan can set accurate CostAttrs’s parameters
1003- Intrinsic::ID FID = VectorIntrinsicID;
1004- unsigned NumOperands = getNumOperands ();
1005- const_operand_range arg_operands =
1006- make_range (op_begin (), op_begin () + getNumOperands ());
1007- if (VPIntrinsic::isVPIntrinsic (VectorIntrinsicID)) {
1008- std::optional<Intrinsic::ID> ID =
1009- VPIntrinsic::getFunctionalIntrinsicIDForVP (VectorIntrinsicID);
1010- if (ID) {
1011- FID = ID.value ();
1012- NumOperands = getNumOperands () - 2 ;
1013- // Remove the Mask && EVL from arg_operands
1014- arg_operands = make_range (op_begin (), op_begin () + getNumOperands () - 2 );
1015- }
1016- }
1017-
1018- for (const auto &[Idx, Op] : enumerate(arg_operands)) {
993+ for (const auto &[Idx, Op] : enumerate(operands ())) {
1019994 auto *V = Op->getUnderlyingValue ();
1020995 if (!V) {
996+ if (VPIntrinsic::isVPIntrinsic (VectorIntrinsicID)) {
997+ Arguments.push_back (V);
998+ break ;
999+ }
10211000 if (auto *UI = dyn_cast_or_null<CallBase>(getUnderlyingValue ())) {
10221001 Arguments.push_back (UI->getArgOperand (Idx));
10231002 continue ;
@@ -1030,14 +1009,14 @@ InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF,
10301009
10311010 Type *RetTy = ToVectorTy (Ctx.Types .inferScalarType (this ), VF);
10321011 SmallVector<Type *> ParamTys;
1033- for (unsigned I = 0 ; I != NumOperands ; ++I)
1012+ for (unsigned I = 0 ; I != getNumOperands () ; ++I)
10341013 ParamTys.push_back (
10351014 ToVectorTy (Ctx.Types .inferScalarType (getOperand (I)), VF));
10361015
10371016 // TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst.
10381017 FastMathFlags FMF = hasFastMathFlags () ? getFastMathFlags () : FastMathFlags ();
10391018 IntrinsicCostAttributes CostAttrs (
1040- FID , RetTy, Arguments, ParamTys, FMF,
1019+ VectorIntrinsicID , RetTy, Arguments, ParamTys, FMF,
10411020 dyn_cast_or_null<IntrinsicInst>(getUnderlyingValue ()));
10421021 return Ctx.TTI .getIntrinsicInstrCost (CostAttrs, CostKind);
10431022}
0 commit comments