Skip to content

Commit 8b525e3

Browse files
committed
[DAGCombine] Pull getSubVectorSrc helper out of narrowInsertExtractVectorBinOp. NFCI.
NFC step towards reusing this in other EXTRACT_SUBVECTOR combines. llvm-svn: 366435
1 parent 7049449 commit 8b525e3

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18002,6 +18002,23 @@ SDValue DAGCombiner::visitCONCAT_VECTORS(SDNode *N) {
1800218002
return SDValue();
1800318003
}
1800418004

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+
1800518022
static SDValue narrowInsertExtractVectorBinOp(SDNode *Extract,
1800618023
SelectionDAG &DAG) {
1800718024
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
@@ -18012,37 +18029,20 @@ static SDValue narrowInsertExtractVectorBinOp(SDNode *Extract,
1801218029

1801318030
SDValue Bop0 = BinOp.getOperand(0), Bop1 = BinOp.getOperand(1);
1801418031
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);
1803518035

1803618036
// TODO: We could handle the case where only 1 operand is being inserted by
1803718037
// creating an extract of the other operand, but that requires checking
1803818038
// number of uses and/or costs.
18039-
if (!Sub0 || !Sub1 || !TLI.isOperationLegalOrCustom(BinOpcode, VT))
18039+
if (!Sub0 || !Sub1 || !TLI.isOperationLegalOrCustom(BinOpcode, SubVT))
1804018040
return SDValue();
1804118041

1804218042
// We are inserting both operands of the wide binop only to extract back
1804318043
// to the narrow vector size. Eliminate all of the insert/extract:
1804418044
// 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,
1804618046
BinOp->getFlags());
1804718047
}
1804818048

0 commit comments

Comments
 (0)