Skip to content

Commit

Permalink
[NFC][SVE] Change useSVEForFixedLengthVectorVT to allow unconditional…
Browse files Browse the repository at this point in the history
… SVE usage for NEON sized vectors.

Previously useSVEForFixedLengthVectorVT only allowed SVE usage when
the target SVE register length was known to be at least 256bit.
This was true even for NEON sized vectors, which was an artificial
restriction imposed during early SVE bring up.  This now changes so
that callers can opt to use SVE for NEON sized vectors regardless
of the SVE register length.

The patch is NFC because for all places where OverrideNEON is used
we now explicitly also check that SVE code generation for larger
than NEON vectors is enabled.  The intent is that over time these
extra checks will either be removed or the lowering disabled if the
SVE usage proves not beneficial.

Differential Revision: https://reviews.llvm.org/D118957
  • Loading branch information
paulwalker-arm committed Feb 4, 2022
1 parent 00bbda0 commit 20085df
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Expand Up @@ -3950,7 +3950,9 @@ SDValue AArch64TargetLowering::LowerMUL(SDValue Op, SelectionDAG &DAG) const {
// If SVE is available then i64 vector multiplications can also be made legal.
bool OverrideNEON = VT == MVT::v2i64 || VT == MVT::v1i64;

if (VT.isScalableVector() || useSVEForFixedLengthVectorVT(VT, OverrideNEON))
if (VT.isScalableVector() ||
useSVEForFixedLengthVectorVT(
VT, OverrideNEON && Subtarget->useSVEForFixedLengthVectors()))
return LowerToPredicatedOp(Op, DAG, AArch64ISD::MUL_PRED);

// Multiplications are only custom-lowered for 128-bit vectors so that
Expand Down Expand Up @@ -4429,8 +4431,9 @@ bool AArch64TargetLowering::shouldRemoveExtendFromGSIndex(EVT VT) const {

bool AArch64TargetLowering::isVectorLoadExtDesirable(SDValue ExtVal) const {
return ExtVal.getValueType().isScalableVector() ||
useSVEForFixedLengthVectorVT(ExtVal.getValueType(),
/*OverrideNEON=*/true);
useSVEForFixedLengthVectorVT(
ExtVal.getValueType(),
/*OverrideNEON=*/Subtarget->useSVEForFixedLengthVectors());
}

unsigned getGatherVecOpcode(bool IsScaled, bool IsSigned, bool NeedsExtend) {
Expand Down Expand Up @@ -4770,7 +4773,9 @@ SDValue AArch64TargetLowering::LowerMLOAD(SDValue Op, SelectionDAG &DAG) const {
assert(LoadNode && "Expected custom lowering of a masked load node");
EVT VT = Op->getValueType(0);

if (useSVEForFixedLengthVectorVT(VT, true))
if (useSVEForFixedLengthVectorVT(
VT,
/*OverrideNEON=*/Subtarget->useSVEForFixedLengthVectors()))
return LowerFixedLengthVectorMLoadToSVE(Op, DAG);

SDValue PassThru = LoadNode->getPassThru();
Expand Down Expand Up @@ -4837,7 +4842,9 @@ SDValue AArch64TargetLowering::LowerSTORE(SDValue Op,
EVT MemVT = StoreNode->getMemoryVT();

if (VT.isVector()) {
if (useSVEForFixedLengthVectorVT(VT, true))
if (useSVEForFixedLengthVectorVT(
VT,
/*OverrideNEON=*/Subtarget->useSVEForFixedLengthVectors()))
return LowerFixedLengthVectorStoreToSVE(Op, DAG);

unsigned AS = StoreNode->getAddressSpace();
Expand Down Expand Up @@ -5262,9 +5269,6 @@ bool AArch64TargetLowering::mergeStoresAfterLegalization(EVT VT) const {

bool AArch64TargetLowering::useSVEForFixedLengthVectorVT(
EVT VT, bool OverrideNEON) const {
if (!Subtarget->useSVEForFixedLengthVectors())
return false;

if (!VT.isFixedLengthVector())
return false;

Expand All @@ -5287,12 +5291,16 @@ bool AArch64TargetLowering::useSVEForFixedLengthVectorVT(

// All SVE implementations support NEON sized vectors.
if (OverrideNEON && (VT.is128BitVector() || VT.is64BitVector()))
return true;
return Subtarget->hasSVE();

// Ensure NEON MVTs only belong to a single register class.
if (VT.getFixedSizeInBits() <= 128)
return false;

// Ensure wider than NEON code generation is enabled.
if (!Subtarget->useSVEForFixedLengthVectors())
return false;

// Don't use SVE for types that don't fit.
if (VT.getFixedSizeInBits() > Subtarget->getMinSVEVectorSizeInBits())
return false;
Expand Down Expand Up @@ -7472,7 +7480,8 @@ SDValue AArch64TargetLowering::LowerCTPOP(SDValue Op, SelectionDAG &DAG) const {
SDValue AArch64TargetLowering::LowerCTTZ(SDValue Op, SelectionDAG &DAG) const {
EVT VT = Op.getValueType();
assert(VT.isScalableVector() ||
useSVEForFixedLengthVectorVT(VT, /*OverrideNEON=*/true));
useSVEForFixedLengthVectorVT(
VT, /*OverrideNEON=*/Subtarget->useSVEForFixedLengthVectors()));

SDLoc DL(Op);
SDValue RBIT = DAG.getNode(ISD::BITREVERSE, DL, VT, Op.getOperand(0));
Expand Down Expand Up @@ -7504,7 +7513,8 @@ SDValue AArch64TargetLowering::LowerMinMax(SDValue Op,
}

if (VT.isScalableVector() ||
useSVEForFixedLengthVectorVT(VT, /*OverrideNEON=*/true)) {
useSVEForFixedLengthVectorVT(
VT, /*OverrideNEON=*/Subtarget->useSVEForFixedLengthVectors())) {
switch (Opcode) {
default:
llvm_unreachable("Wrong instruction");
Expand All @@ -7530,7 +7540,8 @@ SDValue AArch64TargetLowering::LowerBitreverse(SDValue Op,
EVT VT = Op.getValueType();

if (VT.isScalableVector() ||
useSVEForFixedLengthVectorVT(VT, /*OverrideNEON=*/true))
useSVEForFixedLengthVectorVT(
VT, /*OverrideNEON=*/Subtarget->useSVEForFixedLengthVectors()))
return LowerToPredicatedOp(Op, DAG, AArch64ISD::BITREVERSE_MERGE_PASSTHRU);

SDLoc DL(Op);
Expand Down Expand Up @@ -11179,7 +11190,7 @@ SDValue AArch64TargetLowering::LowerDIV(SDValue Op, SelectionDAG &DAG) const {
EVT VT = Op.getValueType();
SDLoc dl(Op);

if (VT.isFixedLengthVector() && Subtarget->hasSVE())
if (useSVEForFixedLengthVectorVT(VT, /*OverrideNEON=*/true))
return LowerFixedLengthVectorIntDivideToSVE(Op, DAG);

assert(VT.isScalableVector() && "Expected a scalable vector.");
Expand Down Expand Up @@ -11576,7 +11587,8 @@ SDValue AArch64TargetLowering::LowerVECREDUCE(SDValue Op,
(Op.getOpcode() != ISD::VECREDUCE_ADD &&
SrcVT.getVectorElementType() == MVT::i64);
if (SrcVT.isScalableVector() ||
useSVEForFixedLengthVectorVT(SrcVT, OverrideNEON)) {
useSVEForFixedLengthVectorVT(
SrcVT, OverrideNEON && Subtarget->useSVEForFixedLengthVectors())) {

if (SrcVT.getVectorElementType() == MVT::i1)
return LowerPredReductionToSVE(Op, DAG);
Expand Down Expand Up @@ -19754,7 +19766,9 @@ SDValue AArch64TargetLowering::LowerReductionToSVE(unsigned Opcode,
SDValue VecOp = ScalarOp.getOperand(0);
EVT SrcVT = VecOp.getValueType();

if (useSVEForFixedLengthVectorVT(SrcVT, true)) {
if (useSVEForFixedLengthVectorVT(
SrcVT,
/*OverrideNEON=*/Subtarget->useSVEForFixedLengthVectors())) {
EVT ContainerVT = getContainerForFixedLengthVector(DAG, SrcVT);
VecOp = convertToScalableVector(DAG, ContainerVT, VecOp);
}
Expand Down

0 comments on commit 20085df

Please sign in to comment.