-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[AArch64] Add custom lowering for load <3 x i8>. #78632
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a786cde
[AArch64] Add custom lowering for load <3 x i8>.
fhahn 192233f
!fixup adjust alignment and pointer info
fhahn 04bd1e5
Merge branch 'main' into aarch64-lower-load-v3i8
fhahn d35da6a
Merge branch 'main' into aarch64-lower-load-v3i8
fhahn 39d6794
!fixup add offset assert and update new tests.
fhahn 748f706
Merge branch 'main' into aarch64-lower-load-v3i8
fhahn e96af2f
!fixup update on top of new test coverage.
fhahn 9800b2c
Merge branch 'main' into aarch64-lower-load-v3i8
fhahn 7e2bf68
!fixup update tests and use MMO.
fhahn 109038b
Try using LD1r.
fhahn e6d5725
!fixup fix formatting
fhahn 491f56d
Merge branch 'main' into aarch64-lower-load-v3i8
fhahn fac6324
Revert "!fixup fix formatting"
fhahn ebb84fc
Revert "Try using LD1r."
fhahn c1013f8
Add note about alternative sequence.
fhahn 445d9be
Merge branch 'main' into aarch64-lower-load-v3i8
fhahn ca48e78
!fixup fix naming + update new tests.
fhahn 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 |
---|---|---|
|
@@ -21248,6 +21248,61 @@ static SDValue foldTruncStoreOfExt(SelectionDAG &DAG, SDNode *N) { | |
return SDValue(); | ||
} | ||
|
||
// A custom combine to lower load <3 x i8> as the more efficient sequence | ||
// below: | ||
// ldrb wX, [x0, #2] | ||
// ldrh wY, [x0] | ||
// orr wX, wY, wX, lsl #16 | ||
// fmov s0, wX | ||
// | ||
// Note that an alternative sequence with even fewer (although usually more | ||
// complex/expensive) instructions would be: | ||
// ld1r.4h { v0 }, [x0], #2 | ||
// ld1.b { v0 }[2], [x0] | ||
// | ||
// Generating this sequence unfortunately results in noticeably worse codegen | ||
// for code that extends the loaded v3i8, due to legalization breaking vector | ||
// shuffle detection in a way that is very difficult to work around. | ||
// TODO: Revisit once v3i8 legalization has been improved in general. | ||
static SDValue combineV3I8LoadExt(LoadSDNode *LD, SelectionDAG &DAG) { | ||
EVT MemVT = LD->getMemoryVT(); | ||
if (MemVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3) || | ||
LD->getOriginalAlign() >= 4) | ||
return SDValue(); | ||
|
||
SDLoc DL(LD); | ||
MachineFunction &MF = DAG.getMachineFunction(); | ||
SDValue Chain = LD->getChain(); | ||
SDValue BasePtr = LD->getBasePtr(); | ||
MachineMemOperand *MMO = LD->getMemOperand(); | ||
assert(LD->getOffset().isUndef() && "undef offset expected"); | ||
|
||
// Load 2 x i8, then 1 x i8. | ||
SDValue L16 = DAG.getLoad(MVT::i16, DL, Chain, BasePtr, MMO); | ||
TypeSize Offset2 = TypeSize::getFixed(2); | ||
SDValue L8 = DAG.getLoad(MVT::i8, DL, Chain, | ||
DAG.getMemBasePlusOffset(BasePtr, Offset2, DL), | ||
MF.getMachineMemOperand(MMO, 2, 1)); | ||
|
||
// Extend to i32. | ||
SDValue Ext16 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, L16); | ||
SDValue Ext8 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, L8); | ||
|
||
// Pack 2 x i8 and 1 x i8 in an i32 and convert to v4i8. | ||
SDValue Shl = DAG.getNode(ISD::SHL, DL, MVT::i32, Ext8, | ||
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. Mismatch between name and operation. 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. Thanks, adjusted! Planning to land this once the pre-commit checks pass. |
||
DAG.getConstant(16, DL, MVT::i32)); | ||
SDValue Or = DAG.getNode(ISD::OR, DL, MVT::i32, Ext16, Shl); | ||
SDValue Cast = DAG.getNode(ISD::BITCAST, DL, MVT::v4i8, Or); | ||
|
||
// Extract v3i8 again. | ||
SDValue Extract = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MemVT, Cast, | ||
DAG.getConstant(0, DL, MVT::i64)); | ||
SDValue TokenFactor = DAG.getNode( | ||
ISD::TokenFactor, DL, MVT::Other, | ||
{SDValue(cast<SDNode>(L16), 1), SDValue(cast<SDNode>(L8), 1)}); | ||
return DAG.getMergeValues({Extract, TokenFactor}, DL); | ||
} | ||
|
||
// Perform TBI simplification if supported by the target and try to break up | ||
// nontemporal loads larger than 256-bits loads for odd types so LDNPQ 256-bit | ||
// load instructions can be selected. | ||
|
@@ -21259,10 +21314,16 @@ static SDValue performLOADCombine(SDNode *N, | |
performTBISimplification(N->getOperand(1), DCI, DAG); | ||
|
||
LoadSDNode *LD = cast<LoadSDNode>(N); | ||
EVT MemVT = LD->getMemoryVT(); | ||
if (LD->isVolatile() || !LD->isNonTemporal() || !Subtarget->isLittleEndian()) | ||
if (LD->isVolatile() || !Subtarget->isLittleEndian()) | ||
return SDValue(N, 0); | ||
inclyc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (SDValue Res = combineV3I8LoadExt(LD, DAG)) | ||
return Res; | ||
|
||
if (!LD->isNonTemporal()) | ||
return SDValue(N, 0); | ||
|
||
EVT MemVT = LD->getMemoryVT(); | ||
if (MemVT.isScalableVector() || MemVT.getSizeInBits() <= 256 || | ||
MemVT.getSizeInBits() % 256 == 0 || | ||
256 % MemVT.getScalarSizeInBits() != 0) | ||
|
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
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.
MachineFunction::getMachineMemOperand has an overload that takes an existing MachineMemOperand and adds an offset; that will produce a more accurate result here.
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.
Thanks updated!