Skip to content

[AArch64][GlobalISel] Allow selecting FPR index loads. #143835

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 1 commit into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5547,9 +5547,15 @@ bool AArch64InstructionSelector::selectIndexedExtLoad(
unsigned MemSizeBits = ExtLd.getMMO().getMemoryType().getSizeInBits();
bool IsPre = ExtLd.isPre();
bool IsSExt = isa<GIndexedSExtLoad>(ExtLd);
bool InsertIntoXReg = false;
unsigned InsertIntoSubReg = 0;
bool IsDst64 = Ty.getSizeInBits() == 64;

// ZExt/SExt should be on gpr but can handle extload and zextload of fpr, so
// long as they are scalar.
bool IsFPR = RBI.getRegBank(Dst, MRI, TRI)->getID() == AArch64::FPRRegBankID;
if ((IsSExt && IsFPR) || Ty.isVector())
return false;

unsigned Opc = 0;
LLT NewLdDstTy;
LLT s32 = LLT::scalar(32);
Expand All @@ -5562,9 +5568,13 @@ bool AArch64InstructionSelector::selectIndexedExtLoad(
else
Opc = IsPre ? AArch64::LDRSBWpre : AArch64::LDRSBWpost;
NewLdDstTy = IsDst64 ? s64 : s32;
} else if (IsFPR) {
Opc = IsPre ? AArch64::LDRBpre : AArch64::LDRBpost;
InsertIntoSubReg = AArch64::bsub;
NewLdDstTy = LLT::scalar(MemSizeBits);
} else {
Opc = IsPre ? AArch64::LDRBBpre : AArch64::LDRBBpost;
InsertIntoXReg = IsDst64;
InsertIntoSubReg = IsDst64 ? AArch64::sub_32 : 0;
NewLdDstTy = s32;
}
} else if (MemSizeBits == 16) {
Expand All @@ -5574,27 +5584,32 @@ bool AArch64InstructionSelector::selectIndexedExtLoad(
else
Opc = IsPre ? AArch64::LDRSHWpre : AArch64::LDRSHWpost;
NewLdDstTy = IsDst64 ? s64 : s32;
} else if (IsFPR) {
Opc = IsPre ? AArch64::LDRHpre : AArch64::LDRHpost;
InsertIntoSubReg = AArch64::hsub;
NewLdDstTy = LLT::scalar(MemSizeBits);
} else {
Opc = IsPre ? AArch64::LDRHHpre : AArch64::LDRHHpost;
InsertIntoXReg = IsDst64;
InsertIntoSubReg = IsDst64 ? AArch64::sub_32 : 0;
NewLdDstTy = s32;
}
} else if (MemSizeBits == 32) {
if (IsSExt) {
Opc = IsPre ? AArch64::LDRSWpre : AArch64::LDRSWpost;
NewLdDstTy = s64;
} else if (IsFPR) {
Opc = IsPre ? AArch64::LDRSpre : AArch64::LDRSpost;
InsertIntoSubReg = AArch64::ssub;
NewLdDstTy = LLT::scalar(MemSizeBits);
} else {
Opc = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
InsertIntoXReg = IsDst64;
InsertIntoSubReg = IsDst64 ? AArch64::sub_32 : 0;
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.
Expand All @@ -5604,15 +5619,18 @@ bool AArch64InstructionSelector::selectIndexedExtLoad(
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) {
// insert into a larger reg if needed.
if (InsertIntoSubReg) {
// 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);
.addImm(InsertIntoSubReg);
RBI.constrainGenericRegister(
SubToReg.getReg(0),
*getRegClassForTypeOnBank(MRI.getType(Dst),
*RBI.getRegBank(Dst, MRI, TRI)),
MRI);
} else {
auto Copy = MIB.buildCopy(Dst, LdMI.getReg(1));
selectCopy(*Copy, TII, MRI, TRI, RBI);
Expand Down
Loading
Loading