[llvm] [AArch64][GlobalISel] Use GPR for illegal fconstants and extend < 32 bit GPR constants to 32 bits (PR #178692)
Ryan Cowan via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 5 02:19:16 PST 2026
================
@@ -358,12 +360,79 @@ AArch64RegisterBankInfo::getInstrAlternativeMappings(
return RegisterBankInfo::getInstrAlternativeMappings(MI);
}
+static bool isLegalFPImm(const MachineInstr &MI, const MachineRegisterInfo &MRI,
+ const AArch64Subtarget &STI) {
+ assert(MI.getOpcode() == TargetOpcode::G_FCONSTANT);
+ Register Dst = MI.getOperand(0).getReg();
+ LLT Ty = MRI.getType(Dst);
+ if (!Ty.isScalar())
+ return false;
+
+ unsigned Bits = Ty.getSizeInBits();
+ if (Bits != 16 && Bits != 32 && Bits != 64)
+ return false;
+
+ EVT VT = EVT::getFloatingPointVT(Bits);
+ bool OptForSize = MI.getMF()->getFunction().hasOptSize() ||
+ MI.getMF()->getFunction().hasMinSize();
+ const AArch64TargetLowering *TLI = STI.getTargetLowering();
+ return TLI->isFPImmLegal(MI.getOperand(1).getFPImm()->getValueAPF(), VT,
+ OptForSize);
+}
+
void AArch64RegisterBankInfo::applyMappingImpl(
MachineIRBuilder &Builder, const OperandsMapper &OpdMapper) const {
MachineInstr &MI = OpdMapper.getMI();
MachineRegisterInfo &MRI = OpdMapper.getMRI();
switch (MI.getOpcode()) {
+ case TargetOpcode::G_CONSTANT: {
+ Register Dst = MI.getOperand(0).getReg();
+ LLT DstTy = MRI.getType(Dst);
+ if (MRI.getRegBank(Dst) == &AArch64::GPRRegBank && DstTy.isScalar() &&
+ DstTy.getSizeInBits() < 32) {
----------------
HolyMolyCowMan wrote:
I think you're right. Constants can't be vectors so we shouldn't see FPR for that reason and G_CONSTANT isn't defined as `onlyUsesFP` or `onlyDefinesFP` so GPR should be chosen.
https://github.com/llvm/llvm-project/pull/178692
More information about the llvm-commits
mailing list