Skip to content

Commit d7a28f7

Browse files
committed
[RISCV] Add asserts for insert/extract_subvector invariants. NFC
We can currently select insert_subvector and extract_subvector nodes in RISCVISelDAGToDAG (this is after custom legalizing in RISCVISelLowering) with fixed subvector types. However decomposeSubvectorInsertExtractToSubRegs is based off of scalable subvectors where the indices are scaled by vscale, so any index other than 0 will be wrong. For insert_subvector the vector being inserted into needs to be undef as well, because it assumes we can replace a whole subregister which isn't always the case for fixed subvectors (e.g. insert <2 x i32> into <4 x i32> at index 0 with vlen=128). We currently maintain these invariants in RISCVISelLowering, so this adds asserts in RISCVISelDAGToDAG so we don't break them.
1 parent 850dde0 commit d7a28f7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,8 +2062,10 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
20622062
const RISCVTargetLowering &TLI = *Subtarget->getTargetLowering();
20632063
MVT SubVecContainerVT = SubVecVT;
20642064
// Establish the correct scalable-vector types for any fixed-length type.
2065-
if (SubVecVT.isFixedLengthVector())
2065+
if (SubVecVT.isFixedLengthVector()) {
2066+
assert(Idx == 0 && V.isUndef());
20662067
SubVecContainerVT = TLI.getContainerForFixedLengthVector(SubVecVT);
2068+
}
20672069
if (VT.isFixedLengthVector())
20682070
VT = TLI.getContainerForFixedLengthVector(VT);
20692071

@@ -2115,8 +2117,10 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
21152117
const RISCVTargetLowering &TLI = *Subtarget->getTargetLowering();
21162118
MVT SubVecContainerVT = VT;
21172119
// Establish the correct scalable-vector types for any fixed-length type.
2118-
if (VT.isFixedLengthVector())
2120+
if (VT.isFixedLengthVector()) {
2121+
assert(Idx == 0);
21192122
SubVecContainerVT = TLI.getContainerForFixedLengthVector(VT);
2123+
}
21202124
if (InVT.isFixedLengthVector())
21212125
InVT = TLI.getContainerForFixedLengthVector(InVT);
21222126

0 commit comments

Comments
 (0)