@@ -18002,6 +18002,23 @@ SDValue DAGCombiner::visitCONCAT_VECTORS(SDNode *N) {
18002
18002
return SDValue();
18003
18003
}
18004
18004
18005
+ // Helper that peeks through INSERT_SUBVECTOR/CONCAT_VECTORS to find
18006
+ // if the subvector can be sourced for free.
18007
+ static SDValue getSubVectorSrc(SDValue V, SDValue Index, EVT SubVT) {
18008
+ if (V.getOpcode() == ISD::INSERT_SUBVECTOR &&
18009
+ V.getOperand(1).getValueType() == SubVT && V.getOperand(2) == Index) {
18010
+ return V.getOperand(1);
18011
+ }
18012
+ auto *IndexC = dyn_cast<ConstantSDNode>(Index);
18013
+ if (IndexC && V.getOpcode() == ISD::CONCAT_VECTORS &&
18014
+ V.getOperand(0).getValueType() == SubVT &&
18015
+ (IndexC->getZExtValue() % SubVT.getVectorNumElements()) == 0) {
18016
+ uint64_t SubIdx = IndexC->getZExtValue() / SubVT.getVectorNumElements();
18017
+ return V.getOperand(SubIdx);
18018
+ }
18019
+ return SDValue();
18020
+ }
18021
+
18005
18022
static SDValue narrowInsertExtractVectorBinOp(SDNode *Extract,
18006
18023
SelectionDAG &DAG) {
18007
18024
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
@@ -18012,37 +18029,20 @@ static SDValue narrowInsertExtractVectorBinOp(SDNode *Extract,
18012
18029
18013
18030
SDValue Bop0 = BinOp.getOperand(0), Bop1 = BinOp.getOperand(1);
18014
18031
SDValue Index = Extract->getOperand(1);
18015
- EVT VT = Extract->getValueType(0);
18016
-
18017
- // Helper that peeks through INSERT_SUBVECTOR/CONCAT_VECTORS to find
18018
- // if the source subvector is the same type as the one being extracted.
18019
- auto GetSubVector = [VT, Index](SDValue V) -> SDValue {
18020
- if (V.getOpcode() == ISD::INSERT_SUBVECTOR &&
18021
- V.getOperand(1).getValueType() == VT && V.getOperand(2) == Index) {
18022
- return V.getOperand(1);
18023
- }
18024
- auto *IndexC = dyn_cast<ConstantSDNode>(Index);
18025
- if (IndexC && V.getOpcode() == ISD::CONCAT_VECTORS &&
18026
- V.getOperand(0).getValueType() == VT &&
18027
- (IndexC->getZExtValue() % VT.getVectorNumElements()) == 0) {
18028
- uint64_t SubIdx = IndexC->getZExtValue() / VT.getVectorNumElements();
18029
- return V.getOperand(SubIdx);
18030
- }
18031
- return SDValue();
18032
- };
18033
- SDValue Sub0 = GetSubVector(Bop0);
18034
- SDValue Sub1 = GetSubVector(Bop1);
18032
+ EVT SubVT = Extract->getValueType(0);
18033
+ SDValue Sub0 = getSubVectorSrc(Bop0, Index, SubVT);
18034
+ SDValue Sub1 = getSubVectorSrc(Bop1, Index, SubVT);
18035
18035
18036
18036
// TODO: We could handle the case where only 1 operand is being inserted by
18037
18037
// creating an extract of the other operand, but that requires checking
18038
18038
// number of uses and/or costs.
18039
- if (!Sub0 || !Sub1 || !TLI.isOperationLegalOrCustom(BinOpcode, VT ))
18039
+ if (!Sub0 || !Sub1 || !TLI.isOperationLegalOrCustom(BinOpcode, SubVT ))
18040
18040
return SDValue();
18041
18041
18042
18042
// We are inserting both operands of the wide binop only to extract back
18043
18043
// to the narrow vector size. Eliminate all of the insert/extract:
18044
18044
// ext (binop (ins ?, X, Index), (ins ?, Y, Index)), Index --> binop X, Y
18045
- return DAG.getNode(BinOpcode, SDLoc(Extract), VT , Sub0, Sub1,
18045
+ return DAG.getNode(BinOpcode, SDLoc(Extract), SubVT , Sub0, Sub1,
18046
18046
BinOp->getFlags());
18047
18047
}
18048
18048
0 commit comments