-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[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
Merged
+444
−95
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,21 @@ 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. | ||
if (!DAG.isSplatValue(N->getOperand(0))) | ||
return SDValue(); | ||
|
||
// interleave splat(X), splat(X).... --> splat(X), splat(X).... | ||
SmallVector<SDValue, 4> Ops; | ||
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)...."? |
||
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) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.