llvm.org GIT mirror llvm / d821478
[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 Simon Pilgrim 4 months ago
1 changed file(s) with 15 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
1788817888 SelectionDAG &DAG) {
1788917889 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1789017890 SDValue BinOp = Extract->getOperand(0);
17891 if (!TLI.isBinOp(BinOp.getOpcode()) || BinOp.getNode()->getNumValues() != 1)
17891 unsigned BinOpcode = BinOp.getOpcode();
17892 if (!TLI.isBinOp(BinOpcode) || BinOp.getNode()->getNumValues() != 1)
1789217893 return SDValue();
1789317894
1789417895 SDValue Bop0 = BinOp.getOperand(0), Bop1 = BinOp.getOperand(1);
1789517896 SDValue Index = Extract->getOperand(1);
1789617897 EVT VT = Extract->getValueType(0);
17897 bool IsInsert0 = Bop0.getOpcode() == ISD::INSERT_SUBVECTOR &&
17898 Bop0.getOperand(1).getValueType() == VT &&
17899 Bop0.getOperand(2) == Index;
17900 bool IsInsert1 = Bop1.getOpcode() == ISD::INSERT_SUBVECTOR &&
17901 Bop1.getOperand(1).getValueType() == VT &&
17902 Bop1.getOperand(2) == Index;
17898
17899 auto GetSubVector = [VT, Index](SDValue V) {
17900 if (V.getOpcode() != ISD::INSERT_SUBVECTOR ||
17901 V.getOperand(1).getValueType() != VT || V.getOperand(2) != Index)
17902 return SDValue();
17903 return V.getOperand(1);
17904 };
17905 SDValue Sub0 = GetSubVector(Bop0);
17906 SDValue Sub1 = GetSubVector(Bop1);
17907
1790317908 // TODO: We could handle the case where only 1 operand is being inserted by
1790417909 // creating an extract of the other operand, but that requires checking
1790517910 // number of uses and/or costs.
17906 if (!IsInsert0 || !IsInsert1 ||
17907 !TLI.isOperationLegalOrCustom(BinOp.getOpcode(), VT))
17911 if (!Sub0 || !Sub1 || !TLI.isOperationLegalOrCustom(BinOpcode, VT))
1790817912 return SDValue();
1790917913
1791017914 // We are inserting both operands of the wide binop only to extract back
1791117915 // to the narrow vector size. Eliminate all of the insert/extract:
1791217916 // ext (binop (ins ?, X, Index), (ins ?, Y, Index)), Index --> binop X, Y
17913 return DAG.getNode(BinOp.getOpcode(), SDLoc(Extract), VT, Bop0.getOperand(1),
17914 Bop1.getOperand(1), BinOp->getFlags());
17917 return DAG.getNode(BinOpcode, SDLoc(Extract), VT, Sub0, Sub1,
17918 BinOp->getFlags());
1791517919 }
1791617920
1791717921 /// If we are extracting a subvector produced by a wide binary operator try