From: Nikita Popov Date: Thu, 29 Oct 2020 19:21:25 +0000 (+0100) Subject: [SDAG] Extract helper to get vecreduce base opcode (NFC) X-Git-Tag: llvmorg-13-init~7702 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91bf17208833ff10e4d3a7e785c9b54ed14b6df2;p=platform%2Fupstream%2Fllvm.git [SDAG] Extract helper to get vecreduce base opcode (NFC) --- diff --git a/llvm/include/llvm/CodeGen/ISDOpcodes.h b/llvm/include/llvm/CodeGen/ISDOpcodes.h index 922cd16..269bb14 100644 --- a/llvm/include/llvm/CodeGen/ISDOpcodes.h +++ b/llvm/include/llvm/CodeGen/ISDOpcodes.h @@ -1166,6 +1166,10 @@ static const int FIRST_TARGET_STRICTFP_OPCODE = BUILTIN_OP_END + 400; /// be used with SelectionDAG::getMemIntrinsicNode. static const int FIRST_TARGET_MEMORY_OPCODE = BUILTIN_OP_END + 500; +/// Get underlying scalar opcode for VECREDUCE opcode. +/// For example ISD::AND for ISD::VECREDUCE_AND. +NodeType getVecReduceBaseOpcode(unsigned VecReduceOpcode); + //===--------------------------------------------------------------------===// /// MemIndexedMode enum - This enum defines the load / store indexed /// addressing modes. diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp index be13209..133a577 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -2143,27 +2143,9 @@ SDValue DAGTypeLegalizer::SplitVecOp_VECREDUCE(SDNode *N, unsigned OpNo) { EVT LoOpVT, HiOpVT; std::tie(LoOpVT, HiOpVT) = DAG.GetSplitDestVTs(VecVT); - unsigned CombineOpc = 0; - switch (N->getOpcode()) { - case ISD::VECREDUCE_FADD: CombineOpc = ISD::FADD; break; - case ISD::VECREDUCE_FMUL: CombineOpc = ISD::FMUL; break; - case ISD::VECREDUCE_ADD: CombineOpc = ISD::ADD; break; - case ISD::VECREDUCE_MUL: CombineOpc = ISD::MUL; break; - case ISD::VECREDUCE_AND: CombineOpc = ISD::AND; break; - case ISD::VECREDUCE_OR: CombineOpc = ISD::OR; break; - case ISD::VECREDUCE_XOR: CombineOpc = ISD::XOR; break; - case ISD::VECREDUCE_SMAX: CombineOpc = ISD::SMAX; break; - case ISD::VECREDUCE_SMIN: CombineOpc = ISD::SMIN; break; - case ISD::VECREDUCE_UMAX: CombineOpc = ISD::UMAX; break; - case ISD::VECREDUCE_UMIN: CombineOpc = ISD::UMIN; break; - case ISD::VECREDUCE_FMAX: CombineOpc = ISD::FMAXNUM; break; - case ISD::VECREDUCE_FMIN: CombineOpc = ISD::FMINNUM; break; - default: - llvm_unreachable("Unexpected reduce ISD node"); - } - // Use the appropriate scalar instruction on the split subvectors before // reducing the now partially reduced smaller vector. + unsigned CombineOpc = ISD::getVecReduceBaseOpcode(N->getOpcode()); SDValue Partial = DAG.getNode(CombineOpc, dl, LoOpVT, Lo, Hi, N->getFlags()); return DAG.getNode(N->getOpcode(), dl, ResVT, Partial, N->getFlags()); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index f05c6a6..8939392 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -333,6 +333,39 @@ bool ISD::matchBinaryPredicate( return true; } +ISD::NodeType ISD::getVecReduceBaseOpcode(unsigned VecReduceOpcode) { + switch (VecReduceOpcode) { + default: + llvm_unreachable("Expected VECREDUCE opcode"); + case ISD::VECREDUCE_FADD: + return ISD::FADD; + case ISD::VECREDUCE_FMUL: + return ISD::FMUL; + case ISD::VECREDUCE_ADD: + return ISD::ADD; + case ISD::VECREDUCE_MUL: + return ISD::MUL; + case ISD::VECREDUCE_AND: + return ISD::AND; + case ISD::VECREDUCE_OR: + return ISD::OR; + case ISD::VECREDUCE_XOR: + return ISD::XOR; + case ISD::VECREDUCE_SMAX: + return ISD::SMAX; + case ISD::VECREDUCE_SMIN: + return ISD::SMIN; + case ISD::VECREDUCE_UMAX: + return ISD::UMAX; + case ISD::VECREDUCE_UMIN: + return ISD::UMIN; + case ISD::VECREDUCE_FMAX: + return ISD::FMAXNUM; + case ISD::VECREDUCE_FMIN: + return ISD::FMINNUM; + } +} + ISD::NodeType ISD::getExtForLoadExtType(bool IsFP, ISD::LoadExtType ExtType) { switch (ExtType) { case ISD::EXTLOAD: diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 716c571..c3c521d8 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -7996,24 +7996,7 @@ bool TargetLowering::expandMULO(SDNode *Node, SDValue &Result, SDValue TargetLowering::expandVecReduce(SDNode *Node, SelectionDAG &DAG) const { SDLoc dl(Node); - unsigned BaseOpcode = 0; - switch (Node->getOpcode()) { - default: llvm_unreachable("Expected VECREDUCE opcode"); - case ISD::VECREDUCE_FADD: BaseOpcode = ISD::FADD; break; - case ISD::VECREDUCE_FMUL: BaseOpcode = ISD::FMUL; break; - case ISD::VECREDUCE_ADD: BaseOpcode = ISD::ADD; break; - case ISD::VECREDUCE_MUL: BaseOpcode = ISD::MUL; break; - case ISD::VECREDUCE_AND: BaseOpcode = ISD::AND; break; - case ISD::VECREDUCE_OR: BaseOpcode = ISD::OR; break; - case ISD::VECREDUCE_XOR: BaseOpcode = ISD::XOR; break; - case ISD::VECREDUCE_SMAX: BaseOpcode = ISD::SMAX; break; - case ISD::VECREDUCE_SMIN: BaseOpcode = ISD::SMIN; break; - case ISD::VECREDUCE_UMAX: BaseOpcode = ISD::UMAX; break; - case ISD::VECREDUCE_UMIN: BaseOpcode = ISD::UMIN; break; - case ISD::VECREDUCE_FMAX: BaseOpcode = ISD::FMAXNUM; break; - case ISD::VECREDUCE_FMIN: BaseOpcode = ISD::FMINNUM; break; - } - + unsigned BaseOpcode = ISD::getVecReduceBaseOpcode(Node->getOpcode()); SDValue Op = Node->getOperand(0); EVT VT = Op.getValueType();