[llvm] [AArch64][GlobalISel] Add support for extending indexed loads. (PR #70373)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 22:29:25 PDT 2023
================
@@ -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);
----------------
tschuett wrote:
You ignore the `false`.
https://github.com/llvm/llvm-project/pull/70373
More information about the llvm-commits
mailing list