Skip to content

Commit 0a06b2a

Browse files
Change from adding ISD::PARTIAL_REDUCE_S/UADD to adding
ISD::PARTIAL_REDUCE_S/UMLA This makes the lowering function easier as you do not need to worry about whether the MUL is lowered or not. Instead its operands are taken from it. If there is no MUL instruction and just one operand, the other operand is a vector of ones (for value types eligible for wide add lowering).
1 parent 5e31db5 commit 0a06b2a

File tree

6 files changed

+34
-44
lines changed

6 files changed

+34
-44
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,8 @@ enum NodeType {
14551455
// unsigned).
14561456
// Operands: Accumulator, Input
14571457
// Outputs: Output
1458-
PARTIAL_REDUCE_SADD,
1459-
PARTIAL_REDUCE_UADD,
1458+
PARTIAL_REDUCE_SMLA,
1459+
PARTIAL_REDUCE_UMLA,
14601460

14611461
// The `llvm.experimental.stackmap` intrinsic.
14621462
// Operands: input chain, glue, <id>, <numShadowBytes>, [live0[, live1...]]

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ class SelectionDAG {
16041604
/// the target's desired shift amount type.
16051605
SDValue getShiftAmountOperand(EVT LHSTy, SDValue Op);
16061606

1607-
/// Expands PARTIAL_REDUCE_S/UADD nodes.
1607+
/// Expands PARTIAL_REDUCE_S/UMLA nodes.
16081608
/// \p Op1 Accumulator for where the result is stored for the partial
16091609
/// reduction operation.
16101610
/// \p Op2 Input for the partial reduction operation.

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8125,7 +8125,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
81258125

81268126
if (!TLI.shouldExpandPartialReductionIntrinsic(cast<IntrinsicInst>(&I))) {
81278127
setValue(&I,
8128-
DAG.getNode(ISD::PARTIAL_REDUCE_UADD, dl, AccVT, Acc, Input));
8128+
DAG.getNode(ISD::PARTIAL_REDUCE_UMLA, dl, AccVT, Acc, Input));
81298129
return;
81308130
}
81318131
setValue(&I, DAG.expandPartialReduceAdd(dl, Acc, Input));

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,10 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
570570
case ISD::VECTOR_FIND_LAST_ACTIVE:
571571
return "find_last_active";
572572

573-
case ISD::PARTIAL_REDUCE_UADD:
574-
return "partial_reduce_uadd";
575-
case ISD::PARTIAL_REDUCE_SADD:
576-
return "partial_reduce_sadd";
573+
case ISD::PARTIAL_REDUCE_UMLA:
574+
return "partial_reduce_umla";
575+
case ISD::PARTIAL_REDUCE_SMLA:
576+
return "partial_reduce_smla";
577577

578578
// Vector Predication
579579
#define BEGIN_REGISTER_VP_SDNODE(SDID, LEGALARG, NAME, ...) \

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
11281128
setTargetDAGCombine(
11291129
{ISD::MGATHER, ISD::MSCATTER, ISD::EXPERIMENTAL_VECTOR_HISTOGRAM});
11301130

1131-
setTargetDAGCombine({ISD::PARTIAL_REDUCE_SADD, ISD::PARTIAL_REDUCE_UADD});
1131+
setTargetDAGCombine({ISD::PARTIAL_REDUCE_SMLA, ISD::PARTIAL_REDUCE_UMLA});
11321132

11331133
setTargetDAGCombine(ISD::FP_EXTEND);
11341134

@@ -1848,14 +1848,14 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
18481848
}
18491849

18501850
for (auto VT : {MVT::nxv2i64, MVT::nxv4i32, MVT::nxv8i16}) {
1851-
setOperationAction(ISD::PARTIAL_REDUCE_UADD, VT, Custom);
1852-
setOperationAction(ISD::PARTIAL_REDUCE_SADD, VT, Custom);
1851+
setOperationAction(ISD::PARTIAL_REDUCE_UMLA, VT, Custom);
1852+
setOperationAction(ISD::PARTIAL_REDUCE_SMLA, VT, Custom);
18531853
}
18541854
}
18551855

18561856
for (auto VT : {MVT::v4i64, MVT::v4i32, MVT::v2i32}) {
1857-
setOperationAction(ISD::PARTIAL_REDUCE_UADD, VT, Custom);
1858-
setOperationAction(ISD::PARTIAL_REDUCE_SADD, VT, Custom);
1857+
setOperationAction(ISD::PARTIAL_REDUCE_UMLA, VT, Custom);
1858+
setOperationAction(ISD::PARTIAL_REDUCE_SMLA, VT, Custom);
18591859
}
18601860

18611861
if (Subtarget->hasMOPS() && Subtarget->hasMTE()) {
@@ -7669,9 +7669,9 @@ SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
76697669
return LowerFLDEXP(Op, DAG);
76707670
case ISD::EXPERIMENTAL_VECTOR_HISTOGRAM:
76717671
return LowerVECTOR_HISTOGRAM(Op, DAG);
7672-
case ISD::PARTIAL_REDUCE_UADD:
7673-
case ISD::PARTIAL_REDUCE_SADD:
7674-
return LowerPARTIAL_REDUCE_ADD(Op, DAG);
7672+
case ISD::PARTIAL_REDUCE_UMLA:
7673+
case ISD::PARTIAL_REDUCE_SMLA:
7674+
return LowerPARTIAL_REDUCE_MLA(Op, DAG);
76757675
}
76767676
}
76777677

@@ -22112,9 +22112,8 @@ SDValue tryCombineToDotProduct(SDValue &Acc, SDValue &Input, SelectionDAG &DAG,
2211222112
return DAG.expandPartialReduceAdd(DL, Acc, Input);
2211322113

2211422114
unsigned NewOpcode =
22115-
AIsSigned ? ISD::PARTIAL_REDUCE_SADD : ISD::PARTIAL_REDUCE_UADD;
22116-
auto NewMul = DAG.getNode(ISD::MUL, DL, A.getValueType(), A, B);
22117-
return DAG.getNode(NewOpcode, DL, AccVT, Acc, NewMul);
22115+
AIsSigned ? ISD::PARTIAL_REDUCE_SMLA : ISD::PARTIAL_REDUCE_UMLA;
22116+
return DAG.getNode(NewOpcode, DL, AccVT, Acc, A, B);
2211822117
}
2211922118

2212022119
SDValue tryCombineToWideAdd(SDValue &Acc, SDValue &Input, SelectionDAG &DAG,
@@ -22136,9 +22135,10 @@ SDValue tryCombineToWideAdd(SDValue &Acc, SDValue &Input, SelectionDAG &DAG,
2213622135
return SDValue();
2213722136

2213822137
unsigned NewOpcode = InputOpcode == ISD::SIGN_EXTEND
22139-
? ISD::PARTIAL_REDUCE_SADD
22140-
: ISD::PARTIAL_REDUCE_UADD;
22141-
return DAG.getNode(NewOpcode, DL, AccVT, Acc, Input);
22138+
? ISD::PARTIAL_REDUCE_SMLA
22139+
: ISD::PARTIAL_REDUCE_UMLA;
22140+
return DAG.getNode(NewOpcode, DL, AccVT, Acc, Input,
22141+
DAG.getConstant(1, DL, InputVT));
2214222142
}
2214322143

2214422144
SDValue performPartialReduceAddCombine(SDNode *N, SelectionDAG &DAG,
@@ -26599,8 +26599,8 @@ SDValue AArch64TargetLowering::PerformDAGCombine(SDNode *N,
2659926599
case ISD::MSCATTER:
2660026600
case ISD::EXPERIMENTAL_VECTOR_HISTOGRAM:
2660126601
return performMaskedGatherScatterCombine(N, DCI, DAG);
26602-
case ISD::PARTIAL_REDUCE_UADD:
26603-
case ISD::PARTIAL_REDUCE_SADD:
26602+
case ISD::PARTIAL_REDUCE_UMLA:
26603+
case ISD::PARTIAL_REDUCE_SMLA:
2660426604
return performPartialReduceAddCombine(N, DAG, Subtarget);
2660526605
case ISD::FP_EXTEND:
2660626606
return performFPExtendCombine(N, DAG, DCI, Subtarget);
@@ -29372,39 +29372,29 @@ SDValue AArch64TargetLowering::LowerVECTOR_HISTOGRAM(SDValue Op,
2937229372
}
2937329373

2937429374
SDValue
29375-
AArch64TargetLowering::LowerPARTIAL_REDUCE_ADD(SDValue Op,
29375+
AArch64TargetLowering::LowerPARTIAL_REDUCE_MLA(SDValue Op,
2937629376
SelectionDAG &DAG) const {
2937729377
SDLoc DL(Op);
2937829378
SDValue Acc = Op.getOperand(0);
29379-
SDValue Input = Op.getOperand(1);
29379+
SDValue Input1 = Op.getOperand(1);
29380+
SDValue Input2 = Op.getOperand(2);
2938029381

2938129382
EVT AccVT = Acc.getValueType();
29382-
EVT InputVT = Input.getValueType();
29383+
EVT InputVT = Input1.getValueType();
2938329384

2938429385
unsigned Opcode = Op.getOpcode();
2938529386

29386-
// If the following condition is true and the input opcode was not ISD::MUL
29387-
// during the DAG-combine, it is already expanded. So this condition means the
29388-
// input opcode must have been ISD::MUL.
2938929387
if (AccVT.getVectorElementCount() * 4 == InputVT.getVectorElementCount()) {
29390-
unsigned IndexAdd = 0;
29391-
// ISD::MUL may have already been lowered, meaning the operands would be in
29392-
// different positions.
29393-
if (Input.getOpcode() != ISD::MUL)
29394-
IndexAdd = 1;
29395-
auto A = Input.getOperand(IndexAdd);
29396-
auto B = Input.getOperand(IndexAdd + 1);
29397-
29398-
unsigned DotOpcode = Opcode == ISD::PARTIAL_REDUCE_SADD ? AArch64ISD::SDOT
29388+
unsigned DotOpcode = Opcode == ISD::PARTIAL_REDUCE_SMLA ? AArch64ISD::SDOT
2939929389
: AArch64ISD::UDOT;
29400-
return DAG.getNode(DotOpcode, DL, AccVT, Acc, A, B);
29390+
return DAG.getNode(DotOpcode, DL, AccVT, Acc, Input1, Input2);
2940129391
}
29402-
bool InputIsSigned = Opcode == ISD::PARTIAL_REDUCE_SADD;
29392+
bool InputIsSigned = Opcode == ISD::PARTIAL_REDUCE_SMLA;
2940329393
unsigned BottomOpcode =
2940429394
InputIsSigned ? AArch64ISD::SADDWB : AArch64ISD::UADDWB;
2940529395
unsigned TopOpcode = InputIsSigned ? AArch64ISD::SADDWT : AArch64ISD::UADDWT;
29406-
auto BottomNode = DAG.getNode(BottomOpcode, DL, AccVT, Acc, Input);
29407-
return DAG.getNode(TopOpcode, DL, AccVT, BottomNode, Input);
29396+
auto BottomNode = DAG.getNode(BottomOpcode, DL, AccVT, Acc, Input1);
29397+
return DAG.getNode(TopOpcode, DL, AccVT, BottomNode, Input1);
2940829398
}
2940929399

2941029400
SDValue

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ class AArch64TargetLowering : public TargetLowering {
11841184
SDValue LowerVECTOR_DEINTERLEAVE(SDValue Op, SelectionDAG &DAG) const;
11851185
SDValue LowerVECTOR_INTERLEAVE(SDValue Op, SelectionDAG &DAG) const;
11861186
SDValue LowerVECTOR_HISTOGRAM(SDValue Op, SelectionDAG &DAG) const;
1187-
SDValue LowerPARTIAL_REDUCE_ADD(SDValue Op, SelectionDAG &DAG) const;
1187+
SDValue LowerPARTIAL_REDUCE_MLA(SDValue Op, SelectionDAG &DAG) const;
11881188
SDValue LowerDIV(SDValue Op, SelectionDAG &DAG) const;
11891189
SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
11901190
SDValue LowerVectorSRA_SRL_SHL(SDValue Op, SelectionDAG &DAG) const;

0 commit comments

Comments
 (0)