-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[AArch64][GlobalISel] Add support for extending indexed loads. #70373
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 all commits
Commits
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 |
---|---|---|
|
@@ -230,6 +230,7 @@ class AArch64InstructionSelector : public InstructionSelector { | |
bool selectMOPS(MachineInstr &I, MachineRegisterInfo &MRI); | ||
bool selectUSMovFromExtend(MachineInstr &I, MachineRegisterInfo &MRI); | ||
|
||
bool selectIndexedExtLoad(MachineInstr &I, MachineRegisterInfo &MRI); | ||
bool selectIndexedLoad(MachineInstr &I, MachineRegisterInfo &MRI); | ||
bool selectIndexedStore(GIndexedStore &I, MachineRegisterInfo &MRI); | ||
|
||
|
@@ -3047,6 +3048,9 @@ bool AArch64InstructionSelector::select(MachineInstr &I) { | |
return constrainSelectedInstRegOperands(*LoadStore, TII, TRI, RBI); | ||
} | ||
|
||
case TargetOpcode::G_INDEXED_ZEXTLOAD: | ||
case TargetOpcode::G_INDEXED_SEXTLOAD: | ||
return selectIndexedExtLoad(I, MRI); | ||
case TargetOpcode::G_INDEXED_LOAD: | ||
return selectIndexedLoad(I, MRI); | ||
case TargetOpcode::G_INDEXED_STORE: | ||
|
@@ -5648,6 +5652,93 @@ MachineInstr *AArch64InstructionSelector::tryAdvSIMDModImmFP( | |
return &*Mov; | ||
} | ||
|
||
bool AArch64InstructionSelector::selectIndexedExtLoad( | ||
MachineInstr &MI, MachineRegisterInfo &MRI) { | ||
auto &ExtLd = cast<GIndexedExtLoad>(MI); | ||
Register Dst = ExtLd.getDstReg(); | ||
Register WriteBack = ExtLd.getWritebackReg(); | ||
Register Base = ExtLd.getBaseReg(); | ||
Register Offset = ExtLd.getOffsetReg(); | ||
LLT Ty = MRI.getType(Dst); | ||
assert(Ty.getSizeInBits() <= 64); // Only for scalar GPRs. | ||
unsigned MemSizeBits = ExtLd.getMMO().getMemoryType().getSizeInBits(); | ||
bool IsPre = ExtLd.isPre(); | ||
bool IsSExt = isa<GIndexedSExtLoad>(ExtLd); | ||
bool InsertIntoXReg = false; | ||
bool IsDst64 = Ty.getSizeInBits() == 64; | ||
|
||
unsigned Opc = 0; | ||
LLT NewLdDstTy; | ||
LLT s32 = LLT::scalar(32); | ||
LLT s64 = LLT::scalar(64); | ||
|
||
if (MemSizeBits == 8) { | ||
if (IsSExt) { | ||
if (IsDst64) | ||
Opc = IsPre ? AArch64::LDRSBXpre : AArch64::LDRSBXpost; | ||
else | ||
Opc = IsPre ? AArch64::LDRSBWpre : AArch64::LDRSBWpost; | ||
NewLdDstTy = IsDst64 ? s64 : s32; | ||
} else { | ||
Opc = IsPre ? AArch64::LDRBBpre : AArch64::LDRBBpost; | ||
InsertIntoXReg = IsDst64; | ||
NewLdDstTy = s32; | ||
} | ||
} else if (MemSizeBits == 16) { | ||
if (IsSExt) { | ||
if (IsDst64) | ||
Opc = IsPre ? AArch64::LDRSHXpre : AArch64::LDRSHXpost; | ||
else | ||
Opc = IsPre ? AArch64::LDRSHWpre : AArch64::LDRSHWpost; | ||
NewLdDstTy = IsDst64 ? s64 : s32; | ||
} else { | ||
Opc = IsPre ? AArch64::LDRHHpre : AArch64::LDRHHpost; | ||
InsertIntoXReg = IsDst64; | ||
NewLdDstTy = s32; | ||
} | ||
} else if (MemSizeBits == 32) { | ||
if (IsSExt) { | ||
Opc = IsPre ? AArch64::LDRSWpre : AArch64::LDRSWpost; | ||
NewLdDstTy = s64; | ||
} else { | ||
Opc = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost; | ||
InsertIntoXReg = IsDst64; | ||
NewLdDstTy = s32; | ||
} | ||
} else { | ||
llvm_unreachable("Unexpected size for indexed load"); | ||
} | ||
|
||
if (RBI.getRegBank(Dst, MRI, TRI)->getID() == AArch64::FPRRegBankID) | ||
return false; // We should be on gpr. | ||
|
||
auto Cst = getIConstantVRegVal(Offset, MRI); | ||
if (!Cst) | ||
return false; // Shouldn't happen, but just in case. | ||
|
||
auto LdMI = MIB.buildInstr(Opc, {WriteBack, NewLdDstTy}, {Base}) | ||
.addImm(Cst->getSExtValue()); | ||
LdMI.cloneMemRefs(ExtLd); | ||
constrainSelectedInstRegOperands(*LdMI, TII, TRI, RBI); | ||
// Make sure to select the load with the MemTy as the dest type, and then | ||
// insert into X reg if needed. | ||
if (InsertIntoXReg) { | ||
// Generate a SUBREG_TO_REG. | ||
auto SubToReg = MIB.buildInstr(TargetOpcode::SUBREG_TO_REG, {Dst}, {}) | ||
.addImm(0) | ||
.addUse(LdMI.getReg(1)) | ||
.addImm(AArch64::sub_32); | ||
RBI.constrainGenericRegister(SubToReg.getReg(0), AArch64::GPR64RegClass, | ||
MRI); | ||
} else { | ||
auto Copy = MIB.buildCopy(Dst, LdMI.getReg(1)); | ||
selectCopy(*Copy, TII, MRI, TRI, RBI); | ||
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. You ignore the |
||
} | ||
MI.eraseFromParent(); | ||
|
||
return true; | ||
} | ||
|
||
bool AArch64InstructionSelector::selectIndexedLoad(MachineInstr &MI, | ||
MachineRegisterInfo &MRI) { | ||
// TODO: extending loads. | ||
|
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
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.
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.
You ignore the
false
.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.
At least
constrainSelectedInstRegOperands
should be[[nodiscard]]
.