[SelectionDAG] Update getNode asserts for EXTRACT/INSERT_SUBVECTOR.

Summary:
The description of EXTACT_SUBVECTOR and INSERT_SUBVECTOR has been
changed to accommodate scalable vectors (see ISDOpcodes.h). This
patch updates the asserts used to verify these requirements when
using SelectionDAG's getNode interface.

This patch introduces the MVT function getVectorMinNumElements
that can be used against fixed-length and scalable vectors when
only the known minimum vector length is required.

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80709
This commit is contained in:
Paul Walker 2020-05-28 10:21:27 +00:00
parent dac21fd29c
commit 92f3d29af0
3 changed files with 35 additions and 17 deletions

View File

@ -292,6 +292,11 @@ namespace llvm {
return {getExtendedVectorNumElements(), isExtendedScalableVector()}; return {getExtendedVectorNumElements(), isExtendedScalableVector()};
} }
/// Given a vector type, return the minimum number of elements it contains.
unsigned getVectorMinNumElements() const {
return getVectorElementCount().Min;
}
/// Return the size of the specified value type in bits. /// Return the size of the specified value type in bits.
/// ///
/// If the value type is a scalable vector type, the scalable property will /// If the value type is a scalable vector type, the scalable property will

View File

@ -706,6 +706,11 @@ namespace llvm {
return { getVectorNumElements(), isScalableVector() }; return { getVectorNumElements(), isScalableVector() };
} }
/// Given a vector type, return the minimum number of elements it contains.
unsigned getVectorMinNumElements() const {
return getVectorElementCount().Min;
}
/// Returns the size of the specified MVT in bits. /// Returns the size of the specified MVT in bits.
/// ///
/// If the value type is a scalable vector type, the scalable property will /// If the value type is a scalable vector type, the scalable property will

View File

@ -5461,21 +5461,24 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
} }
break; break;
case ISD::EXTRACT_SUBVECTOR: case ISD::EXTRACT_SUBVECTOR:
assert(VT.isVector() && N1.getValueType().isVector() && EVT N1VT = N1.getValueType();
"Extract subvector VTs must be a vectors!"); assert(VT.isVector() && N1VT.isVector() &&
assert(VT.getVectorElementType() == "Extract subvector VTs must be vectors!");
N1.getValueType().getVectorElementType() && assert(VT.getVectorElementType() == N1VT.getVectorElementType() &&
"Extract subvector VTs must have the same element type!"); "Extract subvector VTs must have the same element type!");
assert(VT.getVectorNumElements() <= assert((VT.isFixedLengthVector() || N1VT.isScalableVector()) &&
N1.getValueType().getVectorNumElements() && "Cannot extract a scalable vector from a fixed length vector!");
assert((VT.isScalableVector() != N1VT.isScalableVector() ||
VT.getVectorMinNumElements() <= N1VT.getVectorMinNumElements()) &&
"Extract subvector must be from larger vector to smaller vector!"); "Extract subvector must be from larger vector to smaller vector!");
assert(N2C && "Extract subvector index must be a constant"); assert(N2C && "Extract subvector index must be a constant");
assert(VT.getVectorNumElements() + N2C->getZExtValue() <= assert((VT.isScalableVector() != N1VT.isScalableVector() ||
N1.getValueType().getVectorNumElements() && (VT.getVectorMinNumElements() + N2C->getZExtValue()) <=
N1VT.getVectorMinNumElements()) &&
"Extract subvector overflow!"); "Extract subvector overflow!");
// Trivial extraction. // Trivial extraction.
if (VT == N1.getValueType()) if (VT == N1VT)
return N1; return N1;
// EXTRACT_SUBVECTOR of an UNDEF is an UNDEF. // EXTRACT_SUBVECTOR of an UNDEF is an UNDEF.
@ -5665,22 +5668,27 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
// Inserting undef into undef is still undef. // Inserting undef into undef is still undef.
if (N1.isUndef() && N2.isUndef()) if (N1.isUndef() && N2.isUndef())
return getUNDEF(VT); return getUNDEF(VT);
assert(VT.isVector() && N1.getValueType().isVector() &&
N2.getValueType().isVector() && EVT N2VT = N2.getValueType();
"Insert subvector VTs must be a vectors");
assert(VT == N1.getValueType() && assert(VT == N1.getValueType() &&
"Dest and insert subvector source types must match!"); "Dest and insert subvector source types must match!");
assert(N2.getSimpleValueType() <= N1.getSimpleValueType() && assert(VT.isVector() && N2VT.isVector() &&
"Insert subvector VTs must be vectors!");
assert((VT.isScalableVector() || N2VT.isFixedLengthVector()) &&
"Cannot insert a scalable vector into a fixed length vector!");
assert((VT.isScalableVector() != N2VT.isScalableVector() ||
VT.getVectorMinNumElements() >= N2VT.getVectorMinNumElements()) &&
"Insert subvector must be from smaller vector to larger vector!"); "Insert subvector must be from smaller vector to larger vector!");
assert(isa<ConstantSDNode>(N3) && assert(isa<ConstantSDNode>(N3) &&
"Insert subvector index must be constant"); "Insert subvector index must be constant");
assert(N2.getValueType().getVectorNumElements() + assert((VT.isScalableVector() != N2VT.isScalableVector() ||
cast<ConstantSDNode>(N3)->getZExtValue() <= (N2VT.getVectorMinNumElements() +
VT.getVectorNumElements() && cast<ConstantSDNode>(N3)->getZExtValue()) <=
VT.getVectorMinNumElements()) &&
"Insert subvector overflow!"); "Insert subvector overflow!");
// Trivial insertion. // Trivial insertion.
if (VT == N2.getValueType()) if (VT == N2VT)
return N2; return N2;
// If this is an insert of an extracted vector into an undef vector, we // If this is an insert of an extracted vector into an undef vector, we