-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[SelectionDAG][AArch64] Add dot product lowering in NEON for PARTIAL_REDUCE_*MLA ISD nodes #140075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
1ed6ae3
3a1ce17
6e40a1e
5ff49a7
d6d1f56
33088b4
86ca9c6
60e3650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1453,6 +1453,13 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM, | |
| // FADDP custom lowering | ||
| for (MVT VT : { MVT::v16f16, MVT::v8f32, MVT::v4f64 }) | ||
| setOperationAction(ISD::FADD, VT, Custom); | ||
|
|
||
| if (EnablePartialReduceNodes && Subtarget->hasDotProd()) { | ||
NickGuy-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| setPartialReduceMLAAction(MVT::v4i32, MVT::v16i8, Legal); | ||
sdesmalen-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setPartialReduceMLAAction(MVT::v2i32, MVT::v8i8, Legal); | ||
| setPartialReduceMLAAction(MVT::v2i64, MVT::v16i8, Custom); | ||
| } | ||
|
|
||
| } else /* !isNeonAvailable */ { | ||
| for (MVT VT : MVT::fixedlen_vector_valuetypes()) { | ||
| for (unsigned Op = 0; Op < ISD::BUILTIN_OP_END; ++Op) | ||
|
|
@@ -27569,6 +27576,12 @@ void AArch64TargetLowering::ReplaceNodeResults( | |
| if (SDValue Res = LowerVECTOR_COMPRESS(SDValue(N, 0), DAG)) | ||
| Results.push_back(Res); | ||
| return; | ||
| case ISD::PARTIAL_REDUCE_UMLA: | ||
| case ISD::PARTIAL_REDUCE_SMLA: { | ||
| if (SDValue Res = LowerPARTIAL_REDUCE_MLA(SDValue(N, 0), DAG)) | ||
| Results.push_back(Res); | ||
| return; | ||
| } | ||
|
||
| case ISD::ADD: | ||
| case ISD::FADD: | ||
| ReplaceAddWithADDP(N, Results, DAG, Subtarget); | ||
|
|
@@ -29518,37 +29531,60 @@ SDValue AArch64TargetLowering::LowerVECTOR_HISTOGRAM(SDValue Op, | |
| } | ||
|
|
||
| /// If a PARTIAL_REDUCE_MLA node comes in with an accumulator-input type pairing | ||
| /// of nxv2i64/nxv16i8, we cannot directly lower it to a (u|s)dot. We can | ||
| /// of (nx)v2i64/(nx)v16i8, we cannot directly lower it to a (u|s)dot. We can | ||
| /// however still make use of the dot product instruction by instead | ||
| /// accumulating over two steps: nxv16i8 -> nxv4i32 -> nxv2i64. | ||
| /// accumulating over two steps: (nx)v16i8 -> (nx)v4i32 -> (nx)v2i64. | ||
| /// If available, make use of the (U|S)ADDW(B|T) instructions, otherwise | ||
| /// the following pattern is emitted: | ||
| /// add(add(Acc, ext(EXTRACT_SUBVECTOR(N, 0)), ext(EXTRACT_SUBVECTOR(N, | ||
| /// NTy/2)))) | ||
| SDValue | ||
NickGuy-Arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| AArch64TargetLowering::LowerPARTIAL_REDUCE_MLA(SDValue Op, | ||
| SelectionDAG &DAG) const { | ||
NickGuy-Arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| bool Scalable = Op.getValueType().isScalableVector(); | ||
|
|
||
| assert((!Scalable || Subtarget->isSVEorStreamingSVEAvailable()) && | ||
| "SVE or StreamingSVE must be available when using scalable vectors."); | ||
| assert((Scalable || Subtarget->hasDotProd()) && | ||
| "Dotprod must be available when targeting NEON dot product " | ||
| "instructions."); | ||
|
|
||
| SDLoc DL(Op); | ||
|
|
||
| SDValue Acc = Op.getOperand(0); | ||
| SDValue LHS = Op.getOperand(1); | ||
| SDValue RHS = Op.getOperand(2); | ||
| EVT ResultVT = Op.getValueType(); | ||
| assert(ResultVT == MVT::nxv2i64 && LHS.getValueType() == MVT::nxv16i8); | ||
|
|
||
| SDValue DotNode = DAG.getNode(Op.getOpcode(), DL, MVT::nxv4i32, | ||
| DAG.getConstant(0, DL, MVT::nxv4i32), LHS, RHS); | ||
| assert((Scalable && ResultVT == MVT::nxv2i64 && | ||
| LHS.getValueType() == MVT::nxv16i8) || | ||
| (!Scalable && ResultVT == MVT::v2i64 && | ||
| LHS.getValueType() == MVT::v16i8)); | ||
|
|
||
| EVT DotVT = Scalable ? MVT::nxv4i32 : MVT::v4i32; | ||
| SDValue DotNode = DAG.getNode(Op.getOpcode(), DL, DotVT, | ||
| DAG.getConstant(0, DL, DotVT), LHS, RHS); | ||
|
|
||
| bool IsUnsigned = Op.getOpcode() == ISD::PARTIAL_REDUCE_UMLA; | ||
| if (Subtarget->hasSVE2() || Subtarget->isStreamingSVEAvailable()) { | ||
| if (Scalable && | ||
| (Subtarget->hasSVE2() || Subtarget->isStreamingSVEAvailable())) { | ||
| unsigned LoOpcode = IsUnsigned ? AArch64ISD::UADDWB : AArch64ISD::SADDWB; | ||
| unsigned HiOpcode = IsUnsigned ? AArch64ISD::UADDWT : AArch64ISD::SADDWT; | ||
| SDValue Lo = DAG.getNode(LoOpcode, DL, ResultVT, Acc, DotNode); | ||
| return DAG.getNode(HiOpcode, DL, ResultVT, Lo, DotNode); | ||
| } | ||
|
|
||
| unsigned LoOpcode = IsUnsigned ? AArch64ISD::UUNPKLO : AArch64ISD::SUNPKLO; | ||
| unsigned HiOpcode = IsUnsigned ? AArch64ISD::UUNPKHI : AArch64ISD::SUNPKHI; | ||
| auto Lo = DAG.getNode(LoOpcode, DL, ResultVT, DotNode); | ||
| auto Hi = DAG.getNode(HiOpcode, DL, ResultVT, DotNode); | ||
| auto Extended = DAG.getNode(ISD::ADD, DL, ResultVT, Lo, Hi); | ||
| return DAG.getNode(ISD::ADD, DL, ResultVT, Acc, Extended); | ||
| // Fold (nx)v4i32 into (nx)v2i64 | ||
| auto [DotNodeLo, DotNodeHi] = DAG.SplitVector(DotNode, DL); | ||
| if (IsUnsigned) { | ||
| DotNodeLo = DAG.getZExtOrTrunc(DotNodeLo, DL, ResultVT); | ||
| DotNodeHi = DAG.getZExtOrTrunc(DotNodeHi, DL, ResultVT); | ||
| } else { | ||
| DotNodeLo = DAG.getSExtOrTrunc(DotNodeLo, DL, ResultVT); | ||
| DotNodeHi = DAG.getSExtOrTrunc(DotNodeHi, DL, ResultVT); | ||
| } | ||
| auto Lo = DAG.getNode(ISD::ADD, DL, ResultVT, Acc, DotNodeLo); | ||
| return DAG.getNode(ISD::ADD, DL, ResultVT, Lo, DotNodeHi); | ||
MacDue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| SDValue | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.