@@ -2098,32 +2098,43 @@ SDValue SelectionDAG::getCondCode(ISD::CondCode Cond) {
20982098 return SDValue(CondCodeNodes[Cond], 0);
20992099}
21002100
2101- SDValue SelectionDAG::getVScale(const SDLoc &DL, EVT VT, APInt MulImm,
2102- bool ConstantFold) {
2101+ SDValue SelectionDAG::getVScale(const SDLoc &DL, EVT VT, APInt MulImm) {
21032102 assert(MulImm.getBitWidth() == VT.getSizeInBits() &&
21042103 "APInt size does not match type size!");
21052104
21062105 if (MulImm == 0)
21072106 return getConstant(0, DL, VT);
21082107
2109- if (ConstantFold) {
2110- const MachineFunction &MF = getMachineFunction();
2111- const Function &F = MF.getFunction();
2112- ConstantRange CR = getVScaleRange(&F, 64);
2113- if (const APInt *C = CR.getSingleElement())
2114- return getConstant(MulImm * C->getZExtValue(), DL, VT);
2115- }
2108+ const MachineFunction &MF = getMachineFunction();
2109+ const Function &F = MF.getFunction();
2110+ ConstantRange CR = getVScaleRange(&F, 64);
2111+ if (const APInt *C = CR.getSingleElement())
2112+ return getConstant(MulImm * C->getZExtValue(), DL, VT);
21162113
21172114 return getNode(ISD::VSCALE, DL, VT, getConstant(MulImm, DL, VT));
21182115}
21192116
2120- SDValue SelectionDAG::getElementCount(const SDLoc &DL, EVT VT, ElementCount EC,
2121- bool ConstantFold) {
2122- if (EC.isScalable())
2123- return getVScale(DL, VT,
2124- APInt(VT.getSizeInBits(), EC.getKnownMinValue()));
2117+ /// \returns a value of type \p VT that represents the runtime value of \p
2118+ /// Quantity, i.e. scaled by vscale if it's scalable, or a fixed constant
2119+ /// otherwise. Quantity should be a FixedOrScalableQuantity, i.e. ElementCount
2120+ /// or TypeSize.
2121+ template <typename Ty>
2122+ static SDValue getFixedOrScalableQuantity(SelectionDAG &DAG, const SDLoc &DL,
2123+ EVT VT, Ty Quantity) {
2124+ if (Quantity.isScalable())
2125+ return DAG.getVScale(
2126+ DL, VT, APInt(VT.getSizeInBits(), Quantity.getKnownMinValue()));
2127+
2128+ return DAG.getConstant(Quantity.getKnownMinValue(), DL, VT);
2129+ }
2130+
2131+ SDValue SelectionDAG::getElementCount(const SDLoc &DL, EVT VT,
2132+ ElementCount EC) {
2133+ return getFixedOrScalableQuantity(*this, DL, VT, EC);
2134+ }
21252135
2126- return getConstant(EC.getKnownMinValue(), DL, VT);
2136+ SDValue SelectionDAG::getTypeSize(const SDLoc &DL, EVT VT, TypeSize TS) {
2137+ return getFixedOrScalableQuantity(*this, DL, VT, TS);
21272138}
21282139
21292140SDValue SelectionDAG::getStepVector(const SDLoc &DL, EVT ResVT) {
@@ -8500,16 +8511,7 @@ static SDValue getMemsetStringVal(EVT VT, const SDLoc &dl, SelectionDAG &DAG,
85008511SDValue SelectionDAG::getMemBasePlusOffset(SDValue Base, TypeSize Offset,
85018512 const SDLoc &DL,
85028513 const SDNodeFlags Flags) {
8503- EVT VT = Base.getValueType();
8504- SDValue Index;
8505-
8506- if (Offset.isScalable())
8507- Index = getVScale(DL, Base.getValueType(),
8508- APInt(Base.getValueSizeInBits().getFixedValue(),
8509- Offset.getKnownMinValue()));
8510- else
8511- Index = getConstant(Offset.getFixedValue(), DL, VT);
8512-
8514+ SDValue Index = getTypeSize(DL, Base.getValueType(), Offset);
85138515 return getMemBasePlusOffset(Base, Index, DL, Flags);
85148516}
85158517
@@ -13585,11 +13587,8 @@ std::pair<SDValue, SDValue> SelectionDAG::SplitEVL(SDValue N, EVT VecVT,
1358513587 EVT VT = N.getValueType();
1358613588 assert(VecVT.getVectorElementCount().isKnownEven() &&
1358713589 "Expecting the mask to be an evenly-sized vector");
13588- unsigned HalfMinNumElts = VecVT.getVectorMinNumElements() / 2;
13589- SDValue HalfNumElts =
13590- VecVT.isFixedLengthVector()
13591- ? getConstant(HalfMinNumElts, DL, VT)
13592- : getVScale(DL, VT, APInt(VT.getScalarSizeInBits(), HalfMinNumElts));
13590+ SDValue HalfNumElts = getElementCount(
13591+ DL, VT, VecVT.getVectorElementCount().divideCoefficientBy(2));
1359313592 SDValue Lo = getNode(ISD::UMIN, DL, VT, N, HalfNumElts);
1359413593 SDValue Hi = getNode(ISD::USUBSAT, DL, VT, N, HalfNumElts);
1359513594 return std::make_pair(Lo, Hi);
0 commit comments