@@ -1847,17 +1847,32 @@ static SDValue getAllOnesMask(MVT VecVT, SDValue VL, SDLoc DL,
1847
1847
return DAG.getNode(RISCVISD::VMSET_VL, DL, MaskVT, VL);
1848
1848
}
1849
1849
1850
+ static SDValue getVLOp(uint64_t NumElts, SDLoc DL, SelectionDAG &DAG,
1851
+ const RISCVSubtarget &Subtarget) {
1852
+ return DAG.getConstant(NumElts, DL, Subtarget.getXLenVT());
1853
+ }
1854
+
1855
+ static std::pair<SDValue, SDValue>
1856
+ getDefaultVLOps(uint64_t NumElts, MVT ContainerVT, SDLoc DL, SelectionDAG &DAG,
1857
+ const RISCVSubtarget &Subtarget) {
1858
+ assert(ContainerVT.isScalableVector() && "Expecting scalable container type");
1859
+ SDValue VL = getVLOp(NumElts, DL, DAG, Subtarget);
1860
+ SDValue Mask = getAllOnesMask(ContainerVT, VL, DL, DAG);
1861
+ return {Mask, VL};
1862
+ }
1863
+
1850
1864
// Gets the two common "VL" operands: an all-ones mask and the vector length.
1851
1865
// VecVT is a vector type, either fixed-length or scalable, and ContainerVT is
1852
1866
// the vector type that it is contained in.
1853
1867
static std::pair<SDValue, SDValue>
1854
1868
getDefaultVLOps(MVT VecVT, MVT ContainerVT, SDLoc DL, SelectionDAG &DAG,
1855
1869
const RISCVSubtarget &Subtarget) {
1870
+ if (VecVT.isFixedLengthVector())
1871
+ return getDefaultVLOps(VecVT.getVectorNumElements(), ContainerVT, DL, DAG,
1872
+ Subtarget);
1856
1873
assert(ContainerVT.isScalableVector() && "Expecting scalable container type");
1857
1874
MVT XLenVT = Subtarget.getXLenVT();
1858
- SDValue VL = VecVT.isFixedLengthVector()
1859
- ? DAG.getConstant(VecVT.getVectorNumElements(), DL, XLenVT)
1860
- : DAG.getRegister(RISCV::X0, XLenVT);
1875
+ SDValue VL = DAG.getRegister(RISCV::X0, XLenVT);
1861
1876
SDValue Mask = getAllOnesMask(ContainerVT, VL, DL, DAG);
1862
1877
return {Mask, VL};
1863
1878
}
@@ -5115,8 +5130,7 @@ SDValue RISCVTargetLowering::lowerEXTRACT_VECTOR_ELT(SDValue Op,
5115
5130
// If the index is 0, the vector is already in the right position.
5116
5131
if (!isNullConstant(Idx)) {
5117
5132
// Use a VL of 1 to avoid processing more elements than we need.
5118
- SDValue VL = DAG.getConstant(1, DL, XLenVT);
5119
- SDValue Mask = getAllOnesMask(ContainerVT, VL, DL, DAG);
5133
+ auto [Mask, VL] = getDefaultVLOps(1, ContainerVT, DL, DAG, Subtarget);
5120
5134
Vec = DAG.getNode(RISCVISD::VSLIDEDOWN_VL, DL, ContainerVT,
5121
5135
DAG.getUNDEF(ContainerVT), Vec, Idx, Mask, VL);
5122
5136
}
@@ -5486,7 +5500,7 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_W_CHAIN(SDValue Op,
5486
5500
MVT VT = Op->getSimpleValueType(0);
5487
5501
MVT ContainerVT = getContainerForFixedLengthVector(VT);
5488
5502
5489
- SDValue VL = DAG.getConstant (VT.getVectorNumElements(), DL, XLenVT );
5503
+ SDValue VL = getVLOp (VT.getVectorNumElements(), DL, DAG, Subtarget );
5490
5504
SDValue IntID = DAG.getTargetConstant(VlsegInts[NF - 2], DL, XLenVT);
5491
5505
auto *Load = cast<MemIntrinsicSDNode>(Op);
5492
5506
SmallVector<EVT, 9> ContainerVTs(NF, ContainerVT);
@@ -5932,7 +5946,7 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
5932
5946
// Set the vector length to only the number of elements we care about. Note
5933
5947
// that for slideup this includes the offset.
5934
5948
SDValue VL =
5935
- DAG.getConstant (OrigIdx + SubVecVT.getVectorNumElements(), DL, XLenVT );
5949
+ getVLOp (OrigIdx + SubVecVT.getVectorNumElements(), DL, DAG, Subtarget );
5936
5950
SDValue SlideupAmt = DAG.getConstant(OrigIdx, DL, XLenVT);
5937
5951
SDValue Slideup = DAG.getNode(RISCVISD::VSLIDEUP_VL, DL, ContainerVT, Vec,
5938
5952
SubVec, SlideupAmt, Mask, VL);
@@ -6078,7 +6092,7 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
6078
6092
getDefaultVLOps(VecVT, ContainerVT, DL, DAG, Subtarget).first;
6079
6093
// Set the vector length to only the number of elements we care about. This
6080
6094
// avoids sliding down elements we're going to discard straight away.
6081
- SDValue VL = DAG.getConstant (SubVecVT.getVectorNumElements(), DL, XLenVT );
6095
+ SDValue VL = getVLOp (SubVecVT.getVectorNumElements(), DL, DAG, Subtarget );
6082
6096
SDValue SlidedownAmt = DAG.getConstant(OrigIdx, DL, XLenVT);
6083
6097
SDValue Slidedown =
6084
6098
DAG.getNode(RISCVISD::VSLIDEDOWN_VL, DL, ContainerVT,
@@ -6220,7 +6234,7 @@ SDValue RISCVTargetLowering::lowerVECTOR_REVERSE(SDValue Op,
6220
6234
// Calculate VLMAX-1 for the desired SEW.
6221
6235
unsigned MinElts = VecVT.getVectorMinNumElements();
6222
6236
SDValue VLMax = DAG.getNode(ISD::VSCALE, DL, XLenVT,
6223
- DAG.getConstant (MinElts, DL, XLenVT ));
6237
+ getVLOp (MinElts, DL, DAG, Subtarget ));
6224
6238
SDValue VLMinus1 =
6225
6239
DAG.getNode(ISD::SUB, DL, XLenVT, VLMax, DAG.getConstant(1, DL, XLenVT));
6226
6240
@@ -6252,7 +6266,7 @@ SDValue RISCVTargetLowering::lowerVECTOR_SPLICE(SDValue Op,
6252
6266
6253
6267
unsigned MinElts = VecVT.getVectorMinNumElements();
6254
6268
SDValue VLMax = DAG.getNode(ISD::VSCALE, DL, XLenVT,
6255
- DAG.getConstant (MinElts, DL, XLenVT ));
6269
+ getVLOp (MinElts, DL, DAG, Subtarget ));
6256
6270
6257
6271
int64_t ImmValue = cast<ConstantSDNode>(Op.getOperand(2))->getSExtValue();
6258
6272
SDValue DownOffset, UpOffset;
@@ -6292,7 +6306,7 @@ RISCVTargetLowering::lowerFixedLengthVectorLoadToRVV(SDValue Op,
6292
6306
MVT XLenVT = Subtarget.getXLenVT();
6293
6307
MVT ContainerVT = getContainerForFixedLengthVector(VT);
6294
6308
6295
- SDValue VL = DAG.getConstant (VT.getVectorNumElements(), DL, XLenVT );
6309
+ SDValue VL = getVLOp (VT.getVectorNumElements(), DL, DAG, Subtarget );
6296
6310
6297
6311
bool IsMaskOp = VT.getVectorElementType() == MVT::i1;
6298
6312
SDValue IntID = DAG.getTargetConstant(
@@ -6336,7 +6350,7 @@ RISCVTargetLowering::lowerFixedLengthVectorStoreToRVV(SDValue Op,
6336
6350
6337
6351
MVT ContainerVT = getContainerForFixedLengthVector(VT);
6338
6352
6339
- SDValue VL = DAG.getConstant (VT.getVectorNumElements(), DL, XLenVT );
6353
+ SDValue VL = getVLOp (VT.getVectorNumElements(), DL, DAG, Subtarget );
6340
6354
6341
6355
SDValue NewValue =
6342
6356
convertToScalableVector(ContainerVT, StoreVal, DAG, Subtarget);
@@ -6482,11 +6496,9 @@ RISCVTargetLowering::lowerFixedLengthVectorSetccToRVV(SDValue Op,
6482
6496
convertToScalableVector(ContainerVT, Op.getOperand(1), DAG, Subtarget);
6483
6497
6484
6498
SDLoc DL(Op);
6485
- SDValue VL =
6486
- DAG.getConstant(VT.getVectorNumElements(), DL, Subtarget.getXLenVT());
6487
-
6499
+ auto [Mask, VL] = getDefaultVLOps(VT.getVectorNumElements(), ContainerVT, DL,
6500
+ DAG, Subtarget);
6488
6501
MVT MaskVT = getMaskTypeFor(ContainerVT);
6489
- SDValue Mask = getAllOnesMask(ContainerVT, VL, DL, DAG);
6490
6502
6491
6503
SDValue Cmp =
6492
6504
DAG.getNode(RISCVISD::SETCC_VL, DL, MaskVT,
@@ -7720,8 +7732,7 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
7720
7732
MVT XLenVT = Subtarget.getXLenVT();
7721
7733
7722
7734
// Use a VL of 1 to avoid processing more elements than we need.
7723
- SDValue VL = DAG.getConstant(1, DL, XLenVT);
7724
- SDValue Mask = getAllOnesMask(ContainerVT, VL, DL, DAG);
7735
+ auto [Mask, VL] = getDefaultVLOps(1, ContainerVT, DL, DAG, Subtarget);
7725
7736
7726
7737
// Unless the index is known to be 0, we must slide the vector down to get
7727
7738
// the desired element into index 0.
@@ -7783,8 +7794,7 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
7783
7794
7784
7795
// To extract the upper XLEN bits of the vector element, shift the first
7785
7796
// element right by 32 bits and re-extract the lower XLEN bits.
7786
- SDValue VL = DAG.getConstant(1, DL, XLenVT);
7787
- SDValue Mask = getAllOnesMask(VecVT, VL, DL, DAG);
7797
+ auto [Mask, VL] = getDefaultVLOps(1, VecVT, DL, DAG, Subtarget);
7788
7798
7789
7799
SDValue ThirtyTwoV =
7790
7800
DAG.getNode(RISCVISD::VMV_V_X_VL, DL, VecVT, DAG.getUNDEF(VecVT),
0 commit comments