-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[DAGCombiner] Add combine for vector interleave of splats #151110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,6 +331,11 @@ namespace { | |
return CombineTo(N, To, 2, AddTo); | ||
} | ||
|
||
SDValue CombineTo(SDNode *N, SmallVectorImpl<SDValue> *To, | ||
bool AddTo = true) { | ||
return CombineTo(N, To->data(), To->size(), AddTo); | ||
} | ||
|
||
void CommitTargetLoweringOpt(const TargetLowering::TargetLoweringOpt &TLO); | ||
|
||
private: | ||
|
@@ -541,6 +546,7 @@ namespace { | |
SDValue visitEXTRACT_VECTOR_ELT(SDNode *N); | ||
SDValue visitBUILD_VECTOR(SDNode *N); | ||
SDValue visitCONCAT_VECTORS(SDNode *N); | ||
SDValue visitVECTOR_INTERLEAVE(SDNode *N); | ||
SDValue visitEXTRACT_SUBVECTOR(SDNode *N); | ||
SDValue visitVECTOR_SHUFFLE(SDNode *N); | ||
SDValue visitSCALAR_TO_VECTOR(SDNode *N); | ||
|
@@ -2021,6 +2027,7 @@ SDValue DAGCombiner::visit(SDNode *N) { | |
case ISD::EXTRACT_VECTOR_ELT: return visitEXTRACT_VECTOR_ELT(N); | ||
case ISD::BUILD_VECTOR: return visitBUILD_VECTOR(N); | ||
case ISD::CONCAT_VECTORS: return visitCONCAT_VECTORS(N); | ||
case ISD::VECTOR_INTERLEAVE: return visitVECTOR_INTERLEAVE(N); | ||
case ISD::EXTRACT_SUBVECTOR: return visitEXTRACT_SUBVECTOR(N); | ||
case ISD::VECTOR_SHUFFLE: return visitVECTOR_SHUFFLE(N); | ||
case ISD::SCALAR_TO_VECTOR: return visitSCALAR_TO_VECTOR(N); | ||
|
@@ -25274,6 +25281,28 @@ static SDValue combineConcatVectorOfShuffleAndItsOperands( | |
return DAG.getVectorShuffle(VT, dl, ShufOps[0], ShufOps[1], Mask); | ||
} | ||
|
||
static SDValue combineConcatVectorOfSplats(SDNode *N, SelectionDAG &DAG, | ||
const TargetLowering &TLI, | ||
bool LegalTypes, | ||
bool LegalOperations) { | ||
EVT VT = N->getValueType(0); | ||
|
||
// Post-legalization we can only create wider SPLAT_VECTOR operations if both | ||
// the type and operation is legal. The Hexagon target has custom | ||
// legalization for SPLAT_VECTOR that splits the operation into two parts and | ||
// concatenates them. Therefore, custom lowering must also be rejected in | ||
// order to avoid an infinite loop. | ||
if ((LegalTypes && !TLI.isTypeLegal(VT)) || | ||
(LegalOperations && !TLI.isOperationLegal(ISD::SPLAT_VECTOR, VT))) | ||
return SDValue(); | ||
|
||
SDValue Op0 = N->getOperand(0); | ||
if (!llvm::all_equal(N->op_values()) || Op0.getOpcode() != ISD::SPLAT_VECTOR) | ||
return SDValue(); | ||
|
||
return DAG.getNode(ISD::SPLAT_VECTOR, SDLoc(N), VT, Op0.getOperand(0)); | ||
} | ||
|
||
SDValue DAGCombiner::visitCONCAT_VECTORS(SDNode *N) { | ||
// If we only have one input vector, we don't need to do any concatenation. | ||
if (N->getNumOperands() == 1) | ||
|
@@ -25397,6 +25426,10 @@ SDValue DAGCombiner::visitCONCAT_VECTORS(SDNode *N) { | |
return DAG.getBuildVector(VT, SDLoc(N), Opnds); | ||
} | ||
|
||
if (SDValue V = | ||
combineConcatVectorOfSplats(N, DAG, TLI, LegalTypes, LegalOperations)) | ||
return V; | ||
|
||
// Fold CONCAT_VECTORS of only bitcast scalars (or undef) to BUILD_VECTOR. | ||
// FIXME: Add support for concat_vectors(bitcast(vec0),bitcast(vec1),...). | ||
if (SDValue V = combineConcatVectorOfScalars(N, DAG)) | ||
|
@@ -25465,6 +25498,22 @@ SDValue DAGCombiner::visitCONCAT_VECTORS(SDNode *N) { | |
return SDValue(); | ||
} | ||
|
||
SDValue DAGCombiner::visitVECTOR_INTERLEAVE(SDNode *N) { | ||
// Check to see if all operands are identical. | ||
if (!llvm::all_equal(N->op_values())) | ||
return SDValue(); | ||
|
||
// Check to see if the identical operand is a splat. | ||
SDValue Splat = DAG.getSplatValue(N->getOperand(0)); | ||
if (!Splat) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I should have noticed this before but does |
||
return SDValue(); | ||
|
||
// Simply replace all results with the first operand. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps "interleave splat(X), splat(X).... --> splat(X), splat(X)...."? |
||
SmallVector<SDValue, 4> Ops; | ||
Ops.append(N->op_values().begin(), N->op_values().end()); | ||
return CombineTo(N, &Ops); | ||
} | ||
|
||
// Helper that peeks through INSERT_SUBVECTOR/CONCAT_VECTORS to find | ||
// if the subvector can be sourced for free. | ||
static SDValue getSubVectorSrc(SDValue V, unsigned Index, EVT SubVT) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.