Skip to content

Commit

Permalink
[MVT][SVE] Scalable vector MVTs (1/3)
Browse files Browse the repository at this point in the history
This patch adds a few helper functions to obtain new vector
value types based on existing ones without needing to care
about whether they are scalable or not.

I've confined their use to a few common locations right now,
and targets that don't have scalable vectors should never
need to care about these.

Patch by Graham Hunter.

Differential Revision: https://reviews.llvm.org/D32017

llvm-svn: 300838
  • Loading branch information
aemerson committed Apr 20, 2017
1 parent 69883aa commit 5054782
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
11 changes: 11 additions & 0 deletions llvm/include/llvm/CodeGen/ValueTypes.h
Expand Up @@ -304,6 +304,17 @@ namespace llvm {
return EVT::getVectorVT(Context, EltVT, getVectorNumElements());
}

// Return a VT for a vector type with the same element type but
// half the number of elements. The type returned may be an
// extended type.
EVT getHalfNumVectorElementsVT(LLVMContext &Context) const {
EVT EltVT = getVectorElementType();
auto EltCnt = getVectorNumElements();
assert(!(getVectorNumElements() & 1) &&
"Splitting vector, but not in half!");
return EVT::getVectorVT(Context, EltVT, EltCnt / 2);
}

/// Returns true if the given vector is a power of 2.
bool isPow2VectorType() const {
unsigned NElts = getVectorNumElements();
Expand Down
13 changes: 5 additions & 8 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
Expand Up @@ -1293,12 +1293,9 @@ void DAGTypeLegalizer::SplitVecRes_ExtendOp(SDNode *N, SDValue &Lo,
if ((NumElements & 1) == 0 &&
SrcVT.getSizeInBits() * 2 < DestVT.getSizeInBits()) {
LLVMContext &Ctx = *DAG.getContext();
EVT NewSrcVT = EVT::getVectorVT(
Ctx, EVT::getIntegerVT(
Ctx, SrcVT.getScalarSizeInBits() * 2),
NumElements);
EVT SplitSrcVT =
EVT::getVectorVT(Ctx, SrcVT.getVectorElementType(), NumElements / 2);
EVT NewSrcVT = SrcVT.widenIntegerVectorElementType(Ctx);
EVT SplitSrcVT = SrcVT.getHalfNumVectorElementsVT(Ctx);

EVT SplitLoVT, SplitHiVT;
std::tie(SplitLoVT, SplitHiVT) = DAG.GetSplitDestVTs(NewSrcVT);
if (TLI.isTypeLegal(SrcVT) && !TLI.isTypeLegal(SplitSrcVT) &&
Expand Down Expand Up @@ -3012,8 +3009,8 @@ SDValue DAGTypeLegalizer::WidenVSELECTAndMask(SDNode *N) {
// Don't touch if this will be scalarized.
EVT FinalVT = VSelVT;
while (getTypeAction(FinalVT) == TargetLowering::TypeSplitVector)
FinalVT = EVT::getVectorVT(Ctx, FinalVT.getVectorElementType(),
FinalVT.getVectorNumElements() / 2);
FinalVT = FinalVT.getHalfNumVectorElementsVT(Ctx);

if (FinalVT.getVectorNumElements() == 1)
return SDValue();

Expand Down
11 changes: 4 additions & 7 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Expand Up @@ -7573,14 +7573,11 @@ unsigned SelectionDAG::InferPtrAlignment(SDValue Ptr) const {
std::pair<EVT, EVT> SelectionDAG::GetSplitDestVTs(const EVT &VT) const {
// Currently all types are split in half.
EVT LoVT, HiVT;
if (!VT.isVector()) {
if (!VT.isVector())
LoVT = HiVT = TLI->getTypeToTransformTo(*getContext(), VT);
} else {
unsigned NumElements = VT.getVectorNumElements();
assert(!(NumElements & 1) && "Splitting vector, but not in half!");
LoVT = HiVT = EVT::getVectorVT(*getContext(), VT.getVectorElementType(),
NumElements/2);
}
else
LoVT = HiVT = VT.getHalfNumVectorElementsVT(*getContext());

return std::make_pair(LoVT, HiVT);
}

Expand Down

0 comments on commit 5054782

Please sign in to comment.