From 5ac0a2fc48bdfc1165ca66b157cc0c46ba04e6e2 Mon Sep 17 00:00:00 2001 From: Alex Bradbury Date: Wed, 3 Oct 2018 23:30:16 +0000 Subject: [PATCH] [RISCV] Handle redundant SplitF64+BuildPairF64 pairs in a DAGCombine r343712 performed this optimisation during instruction selection. As Eli Friedman pointed out in post-commit review, implementing this as a DAGCombine might allow opportunities for further optimisations. llvm-svn: 343741 --- llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp | 12 ------------ llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 18 ++++++++++++++++++ llvm/lib/Target/RISCV/RISCVISelLowering.h | 2 ++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp index e61086bf0d32..e355b208a75d 100644 --- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp @@ -96,18 +96,6 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) { ReplaceNode(Node, CurDAG->getMachineNode(RISCV::ADDI, DL, VT, TFI, Imm)); return; } - case RISCVISD::SplitF64: { - // If the input to SplitF64 is just BuildPairF64 then the operation is - // redundant. Instead, use BuildPairF64's operands directly. This pattern - // can't be written in tablegen due to the multiple outputs. - SDValue Op0 = Node->getOperand(0); - if (Op0->getOpcode() != RISCVISD::BuildPairF64) - break; - ReplaceUses(SDValue(Node, 0), Op0.getOperand(0)); - ReplaceUses(SDValue(Node, 1), Op0.getOperand(1)); - CurDAG->RemoveDeadNode(Node); - return; - } } // Select the default instruction. diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 695697521838..550c9061eb45 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -494,6 +494,24 @@ SDValue RISCVTargetLowering::LowerRETURNADDR(SDValue Op, return DAG.getCopyFromReg(DAG.getEntryNode(), DL, Reg, XLenVT); } +SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N, + DAGCombinerInfo &DCI) const { + switch (N->getOpcode()) { + default: + break; + case RISCVISD::SplitF64: { + // If the input to SplitF64 is just BuildPairF64 then the operation is + // redundant. Instead, use BuildPairF64's operands directly. + SDValue Op0 = N->getOperand(0); + if (Op0->getOpcode() != RISCVISD::BuildPairF64) + break; + return DCI.CombineTo(N, Op0.getOperand(0), Op0.getOperand(1)); + } + } + + return SDValue(); +} + static MachineBasicBlock *emitSplitF64Pseudo(MachineInstr &MI, MachineBasicBlock *BB) { assert(MI.getOpcode() == RISCV::SplitF64Pseudo && "Unexpected instruction"); diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.h b/llvm/lib/Target/RISCV/RISCVISelLowering.h index e21951140b34..47dbc1af969c 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.h +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.h @@ -58,6 +58,8 @@ public: // Provide custom lowering hooks for some operations. SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; + SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override; + // This method returns the name of a target specific DAG node. const char *getTargetNodeName(unsigned Opcode) const override;