-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[AArch64] Improve lowering for scalable masked interleaving stores #156718
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
Merged
Changes from 3 commits
Commits
Show all changes
4 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
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 |
|---|---|---|
|
|
@@ -24632,6 +24632,104 @@ static SDValue performSTORECombine(SDNode *N, | |
| return SDValue(); | ||
| } | ||
|
|
||
| static bool | ||
| isSequentialConcatOfVectorInterleave(SDNode *N, SmallVectorImpl<SDValue> &Ops) { | ||
| if (N->getOpcode() != ISD::CONCAT_VECTORS) | ||
| return false; | ||
|
|
||
| unsigned NumParts = N->getNumOperands(); | ||
|
|
||
| // We should be concatenating each sequential result from a | ||
| // VECTOR_INTERLEAVE. | ||
| SDNode *InterleaveOp = N->getOperand(0).getNode(); | ||
| if (InterleaveOp->getOpcode() != ISD::VECTOR_INTERLEAVE || | ||
| InterleaveOp->getNumOperands() != NumParts) | ||
| return false; | ||
|
|
||
| for (unsigned I = 0; I < NumParts; I++) { | ||
| if (N->getOperand(I) != SDValue(InterleaveOp, I)) | ||
| return false; | ||
| } | ||
|
|
||
| Ops.append(InterleaveOp->op_begin(), InterleaveOp->op_end()); | ||
| return true; | ||
| } | ||
|
|
||
| static SDValue getNarrowMaskForInterleavedOps(SelectionDAG &DAG, SDLoc &DL, | ||
| SDValue WideMask, | ||
| unsigned RequiredNumParts) { | ||
| if (WideMask->getOpcode() == ISD::CONCAT_VECTORS) { | ||
| SmallVector<SDValue, 4> MaskInterleaveOps; | ||
| if (!isSequentialConcatOfVectorInterleave(WideMask.getNode(), | ||
| MaskInterleaveOps)) | ||
| return SDValue(); | ||
|
|
||
| if (MaskInterleaveOps.size() != RequiredNumParts) | ||
| return SDValue(); | ||
|
|
||
| // Make sure the inputs to the vector interleave are identical. | ||
| if (!llvm::all_equal(MaskInterleaveOps)) | ||
| return SDValue(); | ||
|
|
||
| return MaskInterleaveOps[0]; | ||
| } else if (WideMask->getOpcode() == ISD::SPLAT_VECTOR) { | ||
paulwalker-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ElementCount EC = WideMask.getValueType().getVectorElementCount(); | ||
| assert(EC.isKnownMultipleOf(RequiredNumParts) && | ||
| "Expected element count divisible by number of parts"); | ||
| EC = EC.divideCoefficientBy(RequiredNumParts); | ||
| return DAG.getNode(ISD::SPLAT_VECTOR, DL, MVT::getVectorVT(MVT::i1, EC), | ||
| WideMask->getOperand(0)); | ||
| } | ||
| return SDValue(); | ||
| } | ||
|
|
||
| static SDValue performInterleavedMaskedStoreCombine( | ||
| SDNode *N, TargetLowering::DAGCombinerInfo &DCI, SelectionDAG &DAG) { | ||
c-rhodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!DCI.isBeforeLegalize()) | ||
| return SDValue(); | ||
|
|
||
| MaskedStoreSDNode *MST = cast<MaskedStoreSDNode>(N); | ||
| SDValue WideValue = MST->getValue(); | ||
|
|
||
| // Bail out if the stored value has an unexpected number of uses, since we'll | ||
| // have to peform manual interleaving and may as well just use normal masked | ||
paulwalker-arm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // stores. Also, discard masked stores that are truncating or indexed. | ||
| if (!WideValue.hasOneUse() || !ISD::isNormalMaskedStore(MST) || | ||
| !MST->getOffset().isUndef()) | ||
|
||
| return SDValue(); | ||
|
|
||
| SmallVector<SDValue, 4> ValueInterleaveOps; | ||
| if (!isSequentialConcatOfVectorInterleave(WideValue.getNode(), | ||
| ValueInterleaveOps)) | ||
| return SDValue(); | ||
|
|
||
| unsigned NumParts = ValueInterleaveOps.size(); | ||
| if (NumParts != 2 && NumParts != 4) | ||
| return SDValue(); | ||
|
|
||
| // At the moment we're unlikely to see a fixed-width vector interleave as | ||
| // we usually generate shuffles instead. | ||
c-rhodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| EVT SubVecTy = ValueInterleaveOps[0].getValueType(); | ||
| if (!SubVecTy.isScalableVT() || | ||
| SubVecTy.getSizeInBits().getKnownMinValue() != 128 || | ||
| !DAG.getTargetLoweringInfo().isTypeLegal(SubVecTy)) | ||
| return SDValue(); | ||
|
|
||
| SDLoc DL(N); | ||
| SDValue NarrowMask = | ||
| getNarrowMaskForInterleavedOps(DAG, DL, MST->getMask(), NumParts); | ||
| if (!NarrowMask) | ||
| return SDValue(); | ||
|
|
||
| const Intrinsic::ID IID = | ||
| NumParts == 2 ? Intrinsic::aarch64_sve_st2 : Intrinsic::aarch64_sve_st4; | ||
| SmallVector<SDValue, 8> NewStOps; | ||
| NewStOps.append({MST->getChain(), DAG.getConstant(IID, DL, MVT::i32)}); | ||
c-rhodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| NewStOps.append(ValueInterleaveOps); | ||
| NewStOps.append({NarrowMask, MST->getBasePtr()}); | ||
| return DAG.getNode(ISD::INTRINSIC_VOID, DL, MVT::Other, NewStOps); | ||
| } | ||
|
|
||
| static SDValue performMSTORECombine(SDNode *N, | ||
| TargetLowering::DAGCombinerInfo &DCI, | ||
| SelectionDAG &DAG, | ||
|
|
@@ -24641,6 +24739,9 @@ static SDValue performMSTORECombine(SDNode *N, | |
| SDValue Mask = MST->getMask(); | ||
| SDLoc DL(N); | ||
|
|
||
| if (SDValue Res = performInterleavedMaskedStoreCombine(N, DCI, DAG)) | ||
| return Res; | ||
|
|
||
| // If this is a UZP1 followed by a masked store, fold this into a masked | ||
| // truncating store. We can do this even if this is already a masked | ||
| // truncstore. | ||
|
|
@@ -27274,43 +27375,11 @@ static SDValue performVectorDeinterleaveCombine( | |
| return SDValue(); | ||
|
|
||
| // Now prove that the mask is an interleave of identical masks. | ||
| SDValue Mask = MaskedLoad->getMask(); | ||
| if (Mask->getOpcode() != ISD::SPLAT_VECTOR && | ||
| Mask->getOpcode() != ISD::CONCAT_VECTORS) | ||
| return SDValue(); | ||
|
|
||
| SDValue NarrowMask; | ||
| SDLoc DL(N); | ||
| if (Mask->getOpcode() == ISD::CONCAT_VECTORS) { | ||
| if (Mask->getNumOperands() != NumParts) | ||
| return SDValue(); | ||
|
|
||
| // We should be concatenating each sequential result from a | ||
| // VECTOR_INTERLEAVE. | ||
| SDNode *InterleaveOp = Mask->getOperand(0).getNode(); | ||
| if (InterleaveOp->getOpcode() != ISD::VECTOR_INTERLEAVE || | ||
| InterleaveOp->getNumOperands() != NumParts) | ||
| return SDValue(); | ||
|
|
||
| for (unsigned I = 0; I < NumParts; I++) { | ||
| if (Mask.getOperand(I) != SDValue(InterleaveOp, I)) | ||
| return SDValue(); | ||
| } | ||
|
|
||
| // Make sure the inputs to the vector interleave are identical. | ||
| if (!llvm::all_equal(InterleaveOp->op_values())) | ||
| return SDValue(); | ||
|
|
||
| NarrowMask = InterleaveOp->getOperand(0); | ||
| } else { // ISD::SPLAT_VECTOR | ||
| ElementCount EC = Mask.getValueType().getVectorElementCount(); | ||
| assert(EC.isKnownMultipleOf(NumParts) && | ||
| "Expected element count divisible by number of parts"); | ||
| EC = EC.divideCoefficientBy(NumParts); | ||
| NarrowMask = | ||
| DAG.getNode(ISD::SPLAT_VECTOR, DL, MVT::getVectorVT(MVT::i1, EC), | ||
| Mask->getOperand(0)); | ||
| } | ||
| SDValue NarrowMask = | ||
| getNarrowMaskForInterleavedOps(DAG, DL, MaskedLoad->getMask(), NumParts); | ||
| if (!NarrowMask) | ||
| return SDValue(); | ||
|
|
||
| const Intrinsic::ID IID = NumParts == 2 ? Intrinsic::aarch64_sve_ld2_sret | ||
| : Intrinsic::aarch64_sve_ld4_sret; | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.