From 06fede0c6bce33379560dc7719a114e23f5a0b7a Mon Sep 17 00:00:00 2001 From: Chris Copeland Date: Sun, 23 Feb 2025 00:01:26 -0800 Subject: [PATCH] [ARM] Emit a warning when the hard-float ABI is enabled but can't be used. Compiling for an eabihf target with a CPU lacking floating-point registers will silently use the soft-float ABI instead, even though the Arm attributes section still has Tag_ABI_VFP_args: VFP registers, which leads to silent ABI mismatches at link time. Fixes #110383. --- llvm/lib/Target/ARM/ARMISelLowering.cpp | 4 +++- llvm/test/CodeGen/ARM/eabihf-no-fpregs.ll | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/ARM/eabihf-no-fpregs.ll diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index c7ed73d0e95f7..c54db12379b71 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -791,7 +791,9 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM, setAllExpand(MVT::f32); if (!Subtarget->hasFP64()) setAllExpand(MVT::f64); - } + } else if (TM.Options.FloatABIType == FloatABI::Hard) + errs() << "The hard-float ABI can't be used for a target that " + "doesn't support floating-point (ignoring float-abi)\n"; if (Subtarget->hasFullFP16()) { addRegisterClass(MVT::f16, &ARM::HPRRegClass); diff --git a/llvm/test/CodeGen/ARM/eabihf-no-fpregs.ll b/llvm/test/CodeGen/ARM/eabihf-no-fpregs.ll new file mode 100644 index 0000000000000..dbbf2f3ef0909 --- /dev/null +++ b/llvm/test/CodeGen/ARM/eabihf-no-fpregs.ll @@ -0,0 +1,15 @@ +; RUN: llc -asm-verbose=false --mtriple=armv7-none-eabihf --mattr=+vfp3 < %s | FileCheck %s --check-prefix=CHECK-VFP +; RUN: llc -asm-verbose=false --mtriple=armv7-none-eabi --mattr=-fpregs < %s | FileCheck %s -check-prefix=CHECK-NOVFP +; RUN: llc -asm-verbose=false --mtriple=armv7-none-eabihf --mattr=-fpregs < %s 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR -check-prefix=CHECK-NOVFP + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32" + +; CHECK-VFP: vadd.f32 +; CHECK-ERROR: The hard-float ABI can't be used for a target that doesn't support floating-point (ignoring float-abi) +; CHECK-NOVFP: bl __aeabi_fadd +define float @test_fadd(float %a, float %b) #0 { + %r = fadd float %a, %b + ret float %r +} + +attributes #0 = { nounwind }