Skip to content

Commit 49d5bb4

Browse files
committed
[AArch64][GlobalISel] Materialize 64b FP immediates instead of loading if profitable.
This just mimics what the SDAG backend does.
1 parent d2232e6 commit 49d5bb4

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,12 +2629,17 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
26292629
default:
26302630
llvm_unreachable("Unexpected destination size for G_FCONSTANT?");
26312631
case 32:
2632-
// For s32, use a cp load if we have optsize/minsize.
2633-
if (!shouldOptForSize(&MF))
2632+
case 64: {
2633+
bool OptForSize = shouldOptForSize(&MF);
2634+
const auto &TLI = MF.getSubtarget().getTargetLowering();
2635+
// If TLI says that this fpimm is illegal, then we'll expand to a
2636+
// constant pool load.
2637+
if (TLI->isFPImmLegal(I.getOperand(1).getFPImm()->getValueAPF(),
2638+
EVT::getFloatingPointVT(DefSize), OptForSize))
26342639
break;
26352640
[[fallthrough]];
2641+
}
26362642
case 16:
2637-
case 64:
26382643
case 128: {
26392644
auto *FPImm = I.getOperand(1).getFPImm();
26402645
auto *LoadMI = emitLoadFromConstantPool(FPImm, MIB);
@@ -2648,11 +2653,10 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
26482653
}
26492654
}
26502655

2656+
assert(DefSize == 32 || DefSize == 64 && "Unexpected const def size");
26512657
// Either emit a FMOV, or emit a copy to emit a normal mov.
2652-
assert(DefSize == 32 &&
2653-
"Expected constant pool loads for all sizes other than 32!");
2654-
const Register DefGPRReg =
2655-
MRI.createVirtualRegister(&AArch64::GPR32RegClass);
2658+
const Register DefGPRReg = MRI.createVirtualRegister(
2659+
DefSize == 32 ? &AArch64::GPR32RegClass : &AArch64::GPR64RegClass);
26562660
MachineOperand &RegOp = I.getOperand(0);
26572661
RegOp.setReg(DefGPRReg);
26582662
MIB.setInsertPt(MIB.getMBB(), std::next(I.getIterator()));

llvm/test/CodeGen/AArch64/arm64-fp-imm-size.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc < %s -mtriple=arm64-apple-darwin | FileCheck %s
2+
; RUN: llc < %s -mtriple=arm64-apple-darwin -global-isel | FileCheck %s
23

34
; CHECK: literal8
45
; CHECK: .quad 0x400921fb54442d18

llvm/test/CodeGen/AArch64/arm64-fp-imm.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc < %s -mtriple=arm64-apple-darwin | FileCheck %s
2+
; RUN: llc < %s -mtriple=arm64-apple-darwin -global-isel | FileCheck %s
23

34
; CHECK: literal8
45
; CHECK: .quad 0x400921fb54442d18

llvm/test/CodeGen/AArch64/fpimm.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs < %s | FileCheck %s
22
; RUN: llc -mtriple=aarch64-apple-darwin -code-model=large -verify-machineinstrs < %s | FileCheck %s --check-prefixes=LARGE
33
; RUN: llc -mtriple=aarch64 -code-model=tiny -verify-machineinstrs < %s | FileCheck %s
4+
; RUN: llc -mtriple=aarch64-linux-gnu -global-isel -verify-machineinstrs < %s | FileCheck %s
45

56
@varf32 = global float 0.0
67
@varf64 = global double 0.0

llvm/test/CodeGen/AArch64/sme-disable-gisel-fisel.ll

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,25 @@ define double @locally_streaming_caller_normal_callee(double %x) nounwind noinli
135135
}
136136

137137
define double @normal_caller_to_locally_streaming_callee(double %x) nounwind noinline optnone {
138-
; CHECK-COMMON-LABEL: normal_caller_to_locally_streaming_callee:
139-
; CHECK-COMMON: // %bb.0:
140-
; CHECK-COMMON-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
141-
; CHECK-COMMON-NEXT: bl locally_streaming_caller_normal_callee
142-
; CHECK-COMMON-NEXT: adrp x8, .LCPI3_0
143-
; CHECK-COMMON-NEXT: ldr d1, [x8, :lo12:.LCPI3_0]
144-
; CHECK-COMMON-NEXT: fadd d0, d0, d1
145-
; CHECK-COMMON-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
146-
; CHECK-COMMON-NEXT: ret
138+
; CHECK-FISEL-LABEL: normal_caller_to_locally_streaming_callee:
139+
; CHECK-FISEL: // %bb.0:
140+
; CHECK-FISEL-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
141+
; CHECK-FISEL-NEXT: bl locally_streaming_caller_normal_callee
142+
; CHECK-FISEL-NEXT: adrp x8, .LCPI3_0
143+
; CHECK-FISEL-NEXT: ldr d1, [x8, :lo12:.LCPI3_0]
144+
; CHECK-FISEL-NEXT: fadd d0, d0, d1
145+
; CHECK-FISEL-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
146+
; CHECK-FISEL-NEXT: ret
147+
;
148+
; CHECK-GISEL-LABEL: normal_caller_to_locally_streaming_callee:
149+
; CHECK-GISEL: // %bb.0:
150+
; CHECK-GISEL-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
151+
; CHECK-GISEL-NEXT: bl locally_streaming_caller_normal_callee
152+
; CHECK-GISEL-NEXT: mov x8, #4631107791820423168 // =0x4045000000000000
153+
; CHECK-GISEL-NEXT: fmov d1, x8
154+
; CHECK-GISEL-NEXT: fadd d0, d0, d1
155+
; CHECK-GISEL-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
156+
; CHECK-GISEL-NEXT: ret
147157
%call = call double @locally_streaming_caller_normal_callee(double %x) "aarch64_pstate_sm_body";
148158
%add = fadd double %call, 4.200000e+01
149159
ret double %add;

0 commit comments

Comments
 (0)