Skip to content

Commit e2ccf7f

Browse files
author
Cameron McInally
committed
[SVE] Lower fixed length VECREDUCE_[SMAX|SMIN] to Scalable
This patch is pretty similar to the VECREDUCE_ADD patch, with some minor tweaks. Results from the AArch64ISD::[SMAX|SMIN]V_PRED return element sized results. This requires an ANY_EXTEND for results < 32-bits, since Legalization promotes those results. There is no NEON i64 vector support for SMAXV|SMINV, so use SVE for those. Differential Revision: https://reviews.llvm.org/D88259
1 parent e03dd97 commit e2ccf7f

File tree

2 files changed

+634
-24
lines changed

2 files changed

+634
-24
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,8 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
10921092
setOperationAction(ISD::UMAX, MVT::v2i64, Custom);
10931093
setOperationAction(ISD::UMIN, MVT::v1i64, Custom);
10941094
setOperationAction(ISD::UMIN, MVT::v2i64, Custom);
1095+
setOperationAction(ISD::VECREDUCE_SMAX, MVT::v2i64, Custom);
1096+
setOperationAction(ISD::VECREDUCE_SMIN, MVT::v2i64, Custom);
10951097
}
10961098
}
10971099

@@ -1219,6 +1221,10 @@ void AArch64TargetLowering::addTypeForFixedLengthSVE(MVT VT) {
12191221
setOperationAction(ISD::UMAX, VT, Custom);
12201222
setOperationAction(ISD::UMIN, VT, Custom);
12211223
setOperationAction(ISD::VECREDUCE_ADD, VT, Custom);
1224+
setOperationAction(ISD::VECREDUCE_SMAX, VT, Custom);
1225+
setOperationAction(ISD::VECREDUCE_SMIN, VT, Custom);
1226+
setOperationAction(ISD::VECREDUCE_UMAX, VT, Custom);
1227+
setOperationAction(ISD::VECREDUCE_UMIN, VT, Custom);
12221228
setOperationAction(ISD::VSELECT, VT, Custom);
12231229
setOperationAction(ISD::XOR, VT, Custom);
12241230
setOperationAction(ISD::ZERO_EXTEND, VT, Custom);
@@ -9650,18 +9656,27 @@ static SDValue getReductionSDNode(unsigned Op, SDLoc DL, SDValue ScalarOp,
96509656

96519657
SDValue AArch64TargetLowering::LowerVECREDUCE(SDValue Op,
96529658
SelectionDAG &DAG) const {
9653-
SDValue VecOp = Op.getOperand(0);
9659+
SDValue Src = Op.getOperand(0);
9660+
EVT SrcVT = Src.getValueType();
96549661

96559662
SDLoc dl(Op);
96569663
switch (Op.getOpcode()) {
96579664
case ISD::VECREDUCE_ADD:
9658-
if (useSVEForFixedLengthVectorVT(VecOp.getValueType()))
9665+
if (useSVEForFixedLengthVectorVT(SrcVT))
96599666
return LowerFixedLengthReductionToSVE(AArch64ISD::UADDV_PRED, Op, DAG);
96609667
return getReductionSDNode(AArch64ISD::UADDV, dl, Op, DAG);
9661-
case ISD::VECREDUCE_SMAX:
9668+
case ISD::VECREDUCE_SMAX: {
9669+
bool OverrideNEON = SrcVT.getVectorElementType() == MVT::i64;
9670+
if (useSVEForFixedLengthVectorVT(SrcVT, OverrideNEON))
9671+
return LowerFixedLengthReductionToSVE(AArch64ISD::SMAXV_PRED, Op, DAG);
96629672
return getReductionSDNode(AArch64ISD::SMAXV, dl, Op, DAG);
9663-
case ISD::VECREDUCE_SMIN:
9673+
}
9674+
case ISD::VECREDUCE_SMIN: {
9675+
bool OverrideNEON = SrcVT.getVectorElementType() == MVT::i64;
9676+
if (useSVEForFixedLengthVectorVT(SrcVT, OverrideNEON))
9677+
return LowerFixedLengthReductionToSVE(AArch64ISD::SMINV_PRED, Op, DAG);
96649678
return getReductionSDNode(AArch64ISD::SMINV, dl, Op, DAG);
9679+
}
96659680
case ISD::VECREDUCE_UMAX:
96669681
return getReductionSDNode(AArch64ISD::UMAXV, dl, Op, DAG);
96679682
case ISD::VECREDUCE_UMIN:
@@ -16001,10 +16016,9 @@ SDValue AArch64TargetLowering::LowerFixedLengthReductionToSVE(unsigned Opcode,
1600116016
SDValue Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ResVT,
1600216017
Rdx, DAG.getConstant(0, DL, MVT::i64));
1600316018

16004-
// This is needed for UADDV, since it returns an i64 result. The VEC_REDUCE
16005-
// nodes expect an element size result.
16019+
// The VEC_REDUCE nodes expect an element size result.
1600616020
if (ResVT != ScalarOp.getValueType())
16007-
Res = DAG.getNode(ISD::TRUNCATE, DL, ScalarOp.getValueType(), Res);
16021+
Res = DAG.getAnyExtOrTrunc(Res, DL, ScalarOp.getValueType());
1600816022

1600916023
return Res;
1601016024
}

0 commit comments

Comments
 (0)