From d821478ac9e8d3512a73ee1b1abe26968e820215 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Fri, 21 Jun 2019 14:46:21 +0000 Subject: [PATCH] [DAGCombine] narrowInsertExtractVectorBinOp - reuse "extract from insert" detection code. Move the "extract from insert detection code" into a lambda helper function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364059 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 9c67c3e948c..4f4f502442d 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -17889,30 +17889,34 @@ static SDValue narrowInsertExtractVectorBinOp(SDNode *Extract, SelectionDAG &DAG) { const TargetLowering &TLI = DAG.getTargetLoweringInfo(); SDValue BinOp = Extract->getOperand(0); - if (!TLI.isBinOp(BinOp.getOpcode()) || BinOp.getNode()->getNumValues() != 1) + unsigned BinOpcode = BinOp.getOpcode(); + if (!TLI.isBinOp(BinOpcode) || BinOp.getNode()->getNumValues() != 1) return SDValue(); SDValue Bop0 = BinOp.getOperand(0), Bop1 = BinOp.getOperand(1); SDValue Index = Extract->getOperand(1); EVT VT = Extract->getValueType(0); - bool IsInsert0 = Bop0.getOpcode() == ISD::INSERT_SUBVECTOR && - Bop0.getOperand(1).getValueType() == VT && - Bop0.getOperand(2) == Index; - bool IsInsert1 = Bop1.getOpcode() == ISD::INSERT_SUBVECTOR && - Bop1.getOperand(1).getValueType() == VT && - Bop1.getOperand(2) == Index; + + auto GetSubVector = [VT, Index](SDValue V) { + if (V.getOpcode() != ISD::INSERT_SUBVECTOR || + V.getOperand(1).getValueType() != VT || V.getOperand(2) != Index) + return SDValue(); + return V.getOperand(1); + }; + SDValue Sub0 = GetSubVector(Bop0); + SDValue Sub1 = GetSubVector(Bop1); + // TODO: We could handle the case where only 1 operand is being inserted by // creating an extract of the other operand, but that requires checking // number of uses and/or costs. - if (!IsInsert0 || !IsInsert1 || - !TLI.isOperationLegalOrCustom(BinOp.getOpcode(), VT)) + if (!Sub0 || !Sub1 || !TLI.isOperationLegalOrCustom(BinOpcode, VT)) return SDValue(); // We are inserting both operands of the wide binop only to extract back // to the narrow vector size. Eliminate all of the insert/extract: // ext (binop (ins ?, X, Index), (ins ?, Y, Index)), Index --> binop X, Y - return DAG.getNode(BinOp.getOpcode(), SDLoc(Extract), VT, Bop0.getOperand(1), - Bop1.getOperand(1), BinOp->getFlags()); + return DAG.getNode(BinOpcode, SDLoc(Extract), VT, Sub0, Sub1, + BinOp->getFlags()); } /// If we are extracting a subvector produced by a wide binary operator try -- 2.40.0