Skip to content

Commit 2e56484

Browse files
authored
[RISCV] Use getVectorIdxConstant in RISCVISelLowering.cpp. NFC (#83019)
We use getVectorIdxConstant() in some places and getConstant(XLenVT) or getIntPtrConstant() in others, but getVectorIdxTy() == getPointerTy() == XLenVT. This refactors RISCVISelLowering to use the former for nodes that use getVectorIdxTy(), i.e. INSERT_SUBVECTOR, EXTRACT_SUBVECTOR, INSERT_VECTOR_ELT and EXTRACT_VECTOR_ELT, so that we're consistent.
1 parent b791a51 commit 2e56484

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,7 +2610,7 @@ static SDValue convertToScalableVector(EVT VT, SDValue V, SelectionDAG &DAG,
26102610
assert(V.getValueType().isFixedLengthVector() &&
26112611
"Expected a fixed length vector operand!");
26122612
SDLoc DL(V);
2613-
SDValue Zero = DAG.getConstant(0, DL, Subtarget.getXLenVT());
2613+
SDValue Zero = DAG.getVectorIdxConstant(0, DL);
26142614
return DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, DAG.getUNDEF(VT), V, Zero);
26152615
}
26162616

@@ -3472,7 +3472,7 @@ static SDValue lowerBuildVectorViaDominantValues(SDValue Op, SelectionDAG &DAG,
34723472
continue;
34733473
if (ValueCounts[V] == 1) {
34743474
Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, VT, Vec, V,
3475-
DAG.getConstant(OpIdx.index(), DL, XLenVT));
3475+
DAG.getVectorIdxConstant(OpIdx.index(), DL));
34763476
} else {
34773477
// Blend in all instances of this value using a VSELECT, using a
34783478
// mask where each bit signals whether that element is the one
@@ -3688,7 +3688,7 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
36883688
SDValue Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, ViaVecVT,
36893689
DAG.getUNDEF(ViaVecVT),
36903690
DAG.getConstant(SplatValue, DL, XLenVT),
3691-
DAG.getConstant(0, DL, XLenVT));
3691+
DAG.getVectorIdxConstant(0, DL));
36923692
if (ViaVecLen != 1)
36933693
Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL,
36943694
MVT::getVectorVT(ViaIntVT, 1), Vec,
@@ -4141,9 +4141,9 @@ static SDValue lowerScalarInsert(SDValue Scalar, SDValue VL, MVT VT,
41414141
}
41424142
if (ExtractedContainerVT.bitsLE(VT))
41434143
return DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, Passthru,
4144-
ExtractedVal, DAG.getConstant(0, DL, XLenVT));
4144+
ExtractedVal, DAG.getVectorIdxConstant(0, DL));
41454145
return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, ExtractedVal,
4146-
DAG.getConstant(0, DL, XLenVT));
4146+
DAG.getVectorIdxConstant(0, DL));
41474147
}
41484148
}
41494149

@@ -5020,12 +5020,12 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG,
50205020
assert(EvenSrc >= 0 && "Undef source?");
50215021
EvenV = (EvenSrc / Size) == 0 ? V1 : V2;
50225022
EvenV = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HalfVT, EvenV,
5023-
DAG.getConstant(EvenSrc % Size, DL, XLenVT));
5023+
DAG.getVectorIdxConstant(EvenSrc % Size, DL));
50245024

50255025
assert(OddSrc >= 0 && "Undef source?");
50265026
OddV = (OddSrc / Size) == 0 ? V1 : V2;
50275027
OddV = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HalfVT, OddV,
5028-
DAG.getConstant(OddSrc % Size, DL, XLenVT));
5028+
DAG.getVectorIdxConstant(OddSrc % Size, DL));
50295029

50305030
return getWideningInterleave(EvenV, OddV, DL, DAG, Subtarget);
50315031
}
@@ -6088,7 +6088,7 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
60886088
return SDValue();
60896089
return DAG.getBitcast(VT, DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, BVT,
60906090
DAG.getUNDEF(BVT), Op0,
6091-
DAG.getConstant(0, DL, XLenVT)));
6091+
DAG.getVectorIdxConstant(0, DL)));
60926092
}
60936093
return SDValue();
60946094
}
@@ -6101,7 +6101,7 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
61016101
return SDValue();
61026102
SDValue BVec = DAG.getBitcast(BVT, Op0);
61036103
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, BVec,
6104-
DAG.getConstant(0, DL, XLenVT));
6104+
DAG.getVectorIdxConstant(0, DL));
61056105
}
61066106
return SDValue();
61076107
}
@@ -6600,8 +6600,9 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
66006600
// Don't insert undef subvectors.
66016601
if (SubVec.isUndef())
66026602
continue;
6603-
Vec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, Vec, SubVec,
6604-
DAG.getIntPtrConstant(OpIdx.index() * NumOpElts, DL));
6603+
Vec =
6604+
DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, Vec, SubVec,
6605+
DAG.getVectorIdxConstant(OpIdx.index() * NumOpElts, DL));
66056606
}
66066607
return Vec;
66076608
}
@@ -8404,7 +8405,7 @@ SDValue RISCVTargetLowering::lowerEXTRACT_VECTOR_ELT(SDValue Op,
84048405
if (!EltVT.isInteger()) {
84058406
// Floating-point extracts are handled in TableGen.
84068407
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Vec,
8407-
DAG.getConstant(0, DL, XLenVT));
8408+
DAG.getVectorIdxConstant(0, DL));
84088409
}
84098410

84108411
SDValue Elt0 = DAG.getNode(RISCVISD::VMV_X_S, DL, XLenVT, Vec);
@@ -8837,7 +8838,7 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
88378838
}
88388839
case Intrinsic::riscv_vfmv_f_s:
88398840
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, Op.getValueType(),
8840-
Op.getOperand(1), DAG.getConstant(0, DL, XLenVT));
8841+
Op.getOperand(1), DAG.getVectorIdxConstant(0, DL));
88418842
case Intrinsic::riscv_vmv_v_x:
88428843
return lowerScalarSplat(Op.getOperand(1), Op.getOperand(2),
88438844
Op.getOperand(3), Op.getSimpleValueType(), DL, DAG,
@@ -9437,15 +9438,15 @@ static SDValue lowerReductionSeq(unsigned RVVOpcode, MVT ResVT,
94379438
SDValue InitialValue = lowerScalarInsert(StartValue, InnerVL, InnerVT, DL,
94389439
DAG, Subtarget);
94399440
if (M1VT != InnerVT)
9440-
InitialValue = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, M1VT,
9441-
DAG.getUNDEF(M1VT),
9442-
InitialValue, DAG.getConstant(0, DL, XLenVT));
9441+
InitialValue =
9442+
DAG.getNode(ISD::INSERT_SUBVECTOR, DL, M1VT, DAG.getUNDEF(M1VT),
9443+
InitialValue, DAG.getVectorIdxConstant(0, DL));
94439444
SDValue PassThru = NonZeroAVL ? DAG.getUNDEF(M1VT) : InitialValue;
94449445
SDValue Policy = DAG.getTargetConstant(RISCVII::TAIL_AGNOSTIC, DL, XLenVT);
94459446
SDValue Ops[] = {PassThru, Vec, InitialValue, Mask, VL, Policy};
94469447
SDValue Reduction = DAG.getNode(RVVOpcode, DL, M1VT, Ops);
94479448
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ResVT, Reduction,
9448-
DAG.getConstant(0, DL, XLenVT));
9449+
DAG.getVectorIdxConstant(0, DL));
94499450
}
94509451

94519452
SDValue RISCVTargetLowering::lowerVECREDUCE(SDValue Op,
@@ -9490,9 +9491,8 @@ SDValue RISCVTargetLowering::lowerVECREDUCE(SDValue Op,
94909491
case ISD::UMIN:
94919492
case ISD::SMAX:
94929493
case ISD::SMIN:
9493-
MVT XLenVT = Subtarget.getXLenVT();
94949494
StartV = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VecEltVT, Vec,
9495-
DAG.getConstant(0, DL, XLenVT));
9495+
DAG.getVectorIdxConstant(0, DL));
94969496
}
94979497
return lowerReductionSeq(RVVOpcode, Op.getSimpleValueType(), StartV, Vec,
94989498
Mask, VL, DL, DAG, Subtarget);
@@ -9521,10 +9521,9 @@ getRVVFPReductionOpAndOperands(SDValue Op, SelectionDAG &DAG, EVT EltVT,
95219521
Op.getOperand(0));
95229522
case ISD::VECREDUCE_FMIN:
95239523
case ISD::VECREDUCE_FMAX: {
9524-
MVT XLenVT = Subtarget.getXLenVT();
95259524
SDValue Front =
95269525
DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Op.getOperand(0),
9527-
DAG.getConstant(0, DL, XLenVT));
9526+
DAG.getVectorIdxConstant(0, DL));
95289527
unsigned RVVOpc = (Opcode == ISD::VECREDUCE_FMIN)
95299528
? RISCVISD::VECREDUCE_FMIN_VL
95309529
: RISCVISD::VECREDUCE_FMAX_VL;
@@ -9646,14 +9645,14 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
96469645
if (OrigIdx == 0 && Vec.isUndef() && VecVT.isFixedLengthVector()) {
96479646
SubVec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ContainerVT,
96489647
DAG.getUNDEF(ContainerVT), SubVec,
9649-
DAG.getConstant(0, DL, XLenVT));
9648+
DAG.getVectorIdxConstant(0, DL));
96509649
SubVec = convertFromScalableVector(VecVT, SubVec, DAG, Subtarget);
96519650
return DAG.getBitcast(Op.getValueType(), SubVec);
96529651
}
96539652

96549653
SubVec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ContainerVT,
96559654
DAG.getUNDEF(ContainerVT), SubVec,
9656-
DAG.getConstant(0, DL, XLenVT));
9655+
DAG.getVectorIdxConstant(0, DL));
96579656
SDValue Mask =
96589657
getDefaultVLOps(VecVT, ContainerVT, DL, DAG, Subtarget).first;
96599658
// Set the vector length to only the number of elements we care about. Note
@@ -9720,12 +9719,12 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
97209719
// Extract a subvector equal to the nearest full vector register type. This
97219720
// should resolve to a EXTRACT_SUBREG instruction.
97229721
AlignedExtract = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, InterSubVT, Vec,
9723-
DAG.getConstant(AlignedIdx, DL, XLenVT));
9722+
DAG.getVectorIdxConstant(AlignedIdx, DL));
97249723
}
97259724

97269725
SubVec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, InterSubVT,
97279726
DAG.getUNDEF(InterSubVT), SubVec,
9728-
DAG.getConstant(0, DL, XLenVT));
9727+
DAG.getVectorIdxConstant(0, DL));
97299728

97309729
auto [Mask, VL] = getDefaultScalableVLOps(VecVT, DL, DAG, Subtarget);
97319730

@@ -9751,7 +9750,7 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
97519750
// This should resolve to an INSERT_SUBREG instruction.
97529751
if (VecVT.bitsGT(InterSubVT))
97539752
SubVec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VecVT, Vec, SubVec,
9754-
DAG.getConstant(AlignedIdx, DL, XLenVT));
9753+
DAG.getVectorIdxConstant(AlignedIdx, DL));
97559754

97569755
// We might have bitcast from a mask type: cast back to the original type if
97579756
// required.
@@ -9846,7 +9845,7 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
98469845
DAG.getUNDEF(ContainerVT), Vec, SlidedownAmt, Mask, VL);
98479846
// Now we can use a cast-like subvector extract to get the result.
98489847
Slidedown = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, SubVecVT, Slidedown,
9849-
DAG.getConstant(0, DL, XLenVT));
9848+
DAG.getVectorIdxConstant(0, DL));
98509849
return DAG.getBitcast(Op.getValueType(), Slidedown);
98519850
}
98529851

@@ -9923,7 +9922,7 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
99239922
// Now the vector is in the right position, extract our final subvector. This
99249923
// should resolve to a COPY.
99259924
Slidedown = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, SubVecVT, Slidedown,
9926-
DAG.getConstant(0, DL, XLenVT));
9925+
DAG.getVectorIdxConstant(0, DL));
99279926

99289927
// We might have bitcast from a mask type: cast back to the original type if
99299928
// required.
@@ -9964,7 +9963,6 @@ SDValue RISCVTargetLowering::lowerVECTOR_DEINTERLEAVE(SDValue Op,
99649963
SelectionDAG &DAG) const {
99659964
SDLoc DL(Op);
99669965
MVT VecVT = Op.getSimpleValueType();
9967-
MVT XLenVT = Subtarget.getXLenVT();
99689966

99699967
assert(VecVT.isScalableVector() &&
99709968
"vector_interleave on non-scalable vector!");
@@ -10030,9 +10028,9 @@ SDValue RISCVTargetLowering::lowerVECTOR_DEINTERLEAVE(SDValue Op,
1003010028

1003110029
// Extract the result half of the gather for even and odd
1003210030
SDValue Even = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VecVT, EvenWide,
10033-
DAG.getConstant(0, DL, XLenVT));
10031+
DAG.getVectorIdxConstant(0, DL));
1003410032
SDValue Odd = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VecVT, OddWide,
10035-
DAG.getConstant(0, DL, XLenVT));
10033+
DAG.getVectorIdxConstant(0, DL));
1003610034

1003710035
return DAG.getMergeValues({Even, Odd}, DL);
1003810036
}
@@ -10195,10 +10193,10 @@ SDValue RISCVTargetLowering::lowerVECTOR_REVERSE(SDValue Op,
1019510193
// FIXME: This is a CONCAT_VECTORS.
1019610194
SDValue Res =
1019710195
DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VecVT, DAG.getUNDEF(VecVT), Hi,
10198-
DAG.getIntPtrConstant(0, DL));
10196+
DAG.getVectorIdxConstant(0, DL));
1019910197
return DAG.getNode(
1020010198
ISD::INSERT_SUBVECTOR, DL, VecVT, Res, Lo,
10201-
DAG.getIntPtrConstant(LoVT.getVectorMinNumElements(), DL));
10199+
DAG.getVectorIdxConstant(LoVT.getVectorMinNumElements(), DL));
1020210200
}
1020310201

1020410202
// Just promote the int type to i16 which will double the LMUL.
@@ -10331,9 +10329,9 @@ RISCVTargetLowering::lowerFixedLengthVectorStoreToRVV(SDValue Op,
1033110329
// If the size less than a byte, we need to pad with zeros to make a byte.
1033210330
if (VT.getVectorElementType() == MVT::i1 && VT.getVectorNumElements() < 8) {
1033310331
VT = MVT::v8i1;
10334-
StoreVal = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT,
10335-
DAG.getConstant(0, DL, VT), StoreVal,
10336-
DAG.getIntPtrConstant(0, DL));
10332+
StoreVal =
10333+
DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, DAG.getConstant(0, DL, VT),
10334+
StoreVal, DAG.getVectorIdxConstant(0, DL));
1033710335
}
1033810336

1033910337
MVT ContainerVT = getContainerForFixedLengthVector(VT);
@@ -12109,7 +12107,7 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
1210912107
if (isTypeLegal(BVT)) {
1211012108
SDValue BVec = DAG.getBitcast(BVT, Op0);
1211112109
Results.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, BVec,
12112-
DAG.getConstant(0, DL, XLenVT)));
12110+
DAG.getVectorIdxConstant(0, DL)));
1211312111
}
1211412112
}
1211512113
break;
@@ -12598,7 +12596,7 @@ static SDValue combineBinOpToReduce(SDNode *N, SelectionDAG &DAG,
1259812596
if (ScalarVT != ScalarV.getValueType())
1259912597
NewScalarV =
1260012598
DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ScalarVT, DAG.getUNDEF(ScalarVT),
12601-
NewScalarV, DAG.getConstant(0, DL, Subtarget.getXLenVT()));
12599+
NewScalarV, DAG.getVectorIdxConstant(0, DL));
1260212600

1260312601
SDValue Ops[] = {Reduce.getOperand(0), Reduce.getOperand(1),
1260412602
NewScalarV, Reduce.getOperand(3),
@@ -15248,8 +15246,7 @@ static SDValue performINSERT_VECTOR_ELTCombine(SDNode *N, SelectionDAG &DAG,
1524815246
if (ConcatVT.getVectorElementType() != InVal.getValueType())
1524915247
return SDValue();
1525015248
unsigned ConcatNumElts = ConcatVT.getVectorNumElements();
15251-
SDValue NewIdx = DAG.getConstant(Elt % ConcatNumElts, DL,
15252-
EltNo.getValueType());
15249+
SDValue NewIdx = DAG.getVectorIdxConstant(Elt % ConcatNumElts, DL);
1525315250

1525415251
unsigned ConcatOpIdx = Elt / ConcatNumElts;
1525515252
SDValue ConcatOp = InVec.getOperand(ConcatOpIdx);
@@ -16449,7 +16446,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1644916446
SDValue Result =
1645016447
DAG.getNode(N->getOpcode(), DL, M1VT, M1Passthru, Scalar, VL);
1645116448
Result = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, Passthru, Result,
16452-
DAG.getConstant(0, DL, XLenVT));
16449+
DAG.getVectorIdxConstant(0, DL));
1645316450
return Result;
1645416451
}
1645516452

0 commit comments

Comments
 (0)