diff --git a/llvm/include/llvm/CodeGen/ISDOpcodes.h b/llvm/include/llvm/CodeGen/ISDOpcodes.h --- a/llvm/include/llvm/CodeGen/ISDOpcodes.h +++ b/llvm/include/llvm/CodeGen/ISDOpcodes.h @@ -1363,7 +1363,7 @@ std::optional getBaseOpcodeForVP(unsigned Opcode, bool hasFPExcept); /// Translate this non-VP Opcode to its corresponding VP Opcode. -unsigned getVPForBaseOpcode(unsigned Opcode); +std::optional getVPForBaseOpcode(unsigned Opcode); //===--------------------------------------------------------------------===// /// MemIndexedMode enum - This enum defines the load / store indexed diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -934,62 +934,63 @@ // SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT) { return // DAG.getNode(Opcode, DL, VT); } SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand) { - unsigned VPOpcode = ISD::getVPForBaseOpcode(Opcode); - assert(ISD::getVPMaskIdx(VPOpcode) == 1 && - ISD::getVPExplicitVectorLengthIdx(VPOpcode) == 2); - return DAG.getNode(VPOpcode, DL, VT, + auto VPOpcode = ISD::getVPForBaseOpcode(Opcode); + assert(VPOpcode.has_value() && ISD::getVPMaskIdx(*VPOpcode) == 1 && + ISD::getVPExplicitVectorLengthIdx(*VPOpcode) == 2); + return DAG.getNode(*VPOpcode, DL, VT, {Operand, RootMaskOp, RootVectorLenOp}); } SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, SDValue N2) { - unsigned VPOpcode = ISD::getVPForBaseOpcode(Opcode); - assert(ISD::getVPMaskIdx(VPOpcode) == 2 && - ISD::getVPExplicitVectorLengthIdx(VPOpcode) == 3); - return DAG.getNode(VPOpcode, DL, VT, + auto VPOpcode = ISD::getVPForBaseOpcode(Opcode); + assert(VPOpcode.has_value() && ISD::getVPMaskIdx(*VPOpcode) == 2 && + ISD::getVPExplicitVectorLengthIdx(*VPOpcode) == 3); + return DAG.getNode(*VPOpcode, DL, VT, {N1, N2, RootMaskOp, RootVectorLenOp}); } SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, SDValue N2, SDValue N3) { - unsigned VPOpcode = ISD::getVPForBaseOpcode(Opcode); - assert(ISD::getVPMaskIdx(VPOpcode) == 3 && - ISD::getVPExplicitVectorLengthIdx(VPOpcode) == 4); - return DAG.getNode(VPOpcode, DL, VT, + auto VPOpcode = ISD::getVPForBaseOpcode(Opcode); + assert(VPOpcode.has_value() && ISD::getVPMaskIdx(*VPOpcode) == 3 && + ISD::getVPExplicitVectorLengthIdx(*VPOpcode) == 4); + return DAG.getNode(*VPOpcode, DL, VT, {N1, N2, N3, RootMaskOp, RootVectorLenOp}); } SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand, SDNodeFlags Flags) { - unsigned VPOpcode = ISD::getVPForBaseOpcode(Opcode); - assert(ISD::getVPMaskIdx(VPOpcode) == 1 && - ISD::getVPExplicitVectorLengthIdx(VPOpcode) == 2); - return DAG.getNode(VPOpcode, DL, VT, {Operand, RootMaskOp, RootVectorLenOp}, - Flags); + auto VPOpcode = ISD::getVPForBaseOpcode(Opcode); + assert(VPOpcode.has_value() && ISD::getVPMaskIdx(*VPOpcode) == 1 && + ISD::getVPExplicitVectorLengthIdx(*VPOpcode) == 2); + return DAG.getNode(*VPOpcode, DL, VT, + {Operand, RootMaskOp, RootVectorLenOp}, Flags); } SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, SDValue N2, SDNodeFlags Flags) { - unsigned VPOpcode = ISD::getVPForBaseOpcode(Opcode); - assert(ISD::getVPMaskIdx(VPOpcode) == 2 && - ISD::getVPExplicitVectorLengthIdx(VPOpcode) == 3); - return DAG.getNode(VPOpcode, DL, VT, {N1, N2, RootMaskOp, RootVectorLenOp}, + auto VPOpcode = ISD::getVPForBaseOpcode(Opcode); + assert(VPOpcode.has_value() && ISD::getVPMaskIdx(*VPOpcode) == 2 && + ISD::getVPExplicitVectorLengthIdx(*VPOpcode) == 3); + return DAG.getNode(*VPOpcode, DL, VT, {N1, N2, RootMaskOp, RootVectorLenOp}, Flags); } SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, SDValue N2, SDValue N3, SDNodeFlags Flags) { - unsigned VPOpcode = ISD::getVPForBaseOpcode(Opcode); - assert(ISD::getVPMaskIdx(VPOpcode) == 3 && - ISD::getVPExplicitVectorLengthIdx(VPOpcode) == 4); - return DAG.getNode(VPOpcode, DL, VT, + auto VPOpcode = ISD::getVPForBaseOpcode(Opcode); + assert(VPOpcode.has_value() && ISD::getVPMaskIdx(*VPOpcode) == 3 && + ISD::getVPExplicitVectorLengthIdx(*VPOpcode) == 4); + return DAG.getNode(*VPOpcode, DL, VT, {N1, N2, N3, RootMaskOp, RootVectorLenOp}, Flags); } bool isOperationLegalOrCustom(unsigned Op, EVT VT, bool LegalOnly = false) const { - unsigned VPOp = ISD::getVPForBaseOpcode(Op); - return TLI.isOperationLegalOrCustom(VPOp, VT, LegalOnly); + auto VPOp = ISD::getVPForBaseOpcode(Op); + assert(VPOp.has_value()); + return TLI.isOperationLegalOrCustom(*VPOp, VT, LegalOnly); } }; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -531,10 +531,10 @@ return std::nullopt; } -unsigned ISD::getVPForBaseOpcode(unsigned Opcode) { +std::optional ISD::getVPForBaseOpcode(unsigned Opcode) { switch (Opcode) { default: - llvm_unreachable("can not translate this Opcode to VP."); + return std::nullopt; #define BEGIN_REGISTER_VP_SDNODE(VPOPC, ...) break; #define VP_PROPERTY_FUNCTIONAL_SDOPC(SDOPC) case ISD::SDOPC: #define END_REGISTER_VP_SDNODE(VPOPC) return ISD::VPOPC;