[llvm] a424bbf - ARM: Read float ABI from the "float-abi" module flag (#212981)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 03:24:29 PDT 2026


Author: Matt Arsenault
Date: 2026-08-12T10:24:23Z
New Revision: a424bbfe0714773a3f54c6d6b46600370343a049

URL: https://github.com/llvm/llvm-project/commit/a424bbfe0714773a3f54c6d6b46600370343a049
DIFF: https://github.com/llvm/llvm-project/commit/a424bbfe0714773a3f54c6d6b46600370343a049.diff

LOG: ARM: Read float ABI from the "float-abi" module flag (#212981)

Use the value from the module flag if present, otherwise
fall back on the legacy TargetOptions field until that is
removed.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>

Added: 
    llvm/test/CodeGen/ARM/float-abi-module-flag.ll

Modified: 
    llvm/lib/Target/ARM/ARMAsmPrinter.cpp
    llvm/lib/Target/ARM/ARMTargetMachine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 34b83d3aefb2f..59ad547dc26d7 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -698,8 +698,13 @@ void ARMAsmPrinter::emitAttributes() {
   }
   const ARMBaseTargetMachine &ATM =
       static_cast<const ARMBaseTargetMachine &>(TM);
+  // The float ABI comes from the "float-abi" module flag if present, otherwise
+  // from the legacy -float-abi target option.
+  FloatABI::ABIType FloatABI = MMI->getModule()->getFloatABI();
+  if (FloatABI == FloatABI::Default)
+    FloatABI = ATM.Options.FloatABIType;
   const ARMSubtarget STI(TT, std::string(CPU), ArchFS, ATM,
-                         ATM.isLittleEndian(), ATM.Options.FloatABIType);
+                         ATM.isLittleEndian(), FloatABI);
 
   // Emit build attributes for the available hardware.
   ATS.emitTargetAttributes(STI);

diff  --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
index 9df4123fd3193..3d388a7db6687 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
@@ -37,6 +37,7 @@
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Pass.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -237,7 +238,15 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
   if (DM != DenormalMode::getIEEE())
     Key += "denormal-fp-math=" + DM.str();
 
-  FloatABI::ABIType FloatABI = this->Options.FloatABIType;
+  // The float ABI comes from the "float-abi" module flag if present, otherwise
+  // from the legacy -float-abi target option (which the constructor seeded from
+  // the target triple).
+  FloatABI::ABIType FloatABI = F.getParent()->getFloatABI();
+  if (FloatABI == FloatABI::Default) {
+    FloatABI = Options.FloatABIType;
+    assert(FloatABI != FloatABI::Default &&
+           "expected TargetMachine constructor to overwrite default float abi");
+  }
 
   // It is legal to have FloatABI::Hard with +soft-float for targets with SIMD
   // registers, but no floating-point hardware (mve+nofp)

diff  --git a/llvm/test/CodeGen/ARM/float-abi-module-flag.ll b/llvm/test/CodeGen/ARM/float-abi-module-flag.ll
new file mode 100644
index 0000000000000..ea57078c619bd
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/float-abi-module-flag.ll
@@ -0,0 +1,43 @@
+; The "float-abi" module flag selects the floating-point calling convention.
+; RUN: split-file %s %t
+
+; Hard float ABI module flag: FP argument returned in a VFP register (s0).
+; RUN: llc -mtriple=armv7-none-eabi -mattr=+vfp3 < %t/hard.ll | FileCheck %s --check-prefix=HARD
+
+; Soft float ABI module flag: FP argument returned in a GPR (r0).
+; RUN: llc -mtriple=armv7-none-eabi -mattr=+vfp3 < %t/soft.ll | FileCheck %s --check-prefix=SOFT
+
+; No module flag: the -float-abi command-line option still applies.
+; RUN: llc -mtriple=armv7-none-eabi -mattr=+vfp3 -float-abi=hard < %t/none.ll | FileCheck %s --check-prefix=HARD
+; RUN: llc -mtriple=armv7-none-eabi -mattr=+vfp3 -float-abi=soft < %t/none.ll | FileCheck %s --check-prefix=SOFT
+
+; The triple default applies with no module flag.
+; RUN: llc -mtriple=armv7-none-eabi -mattr=+vfp3 < %t/none.ll | FileCheck %s --check-prefix=SOFT
+
+; An explicit module flag takes precedence over a conflicting -float-abi option.
+; RUN: llc -mtriple=armv7-none-eabi -mattr=+vfp3 -float-abi=soft < %t/hard.ll | FileCheck %s --check-prefix=HARD
+; RUN: llc -mtriple=armv7-none-eabi -mattr=+vfp3 -float-abi=hard < %t/soft.ll | FileCheck %s --check-prefix=SOFT
+
+;--- hard.ll
+define float @f(float %x) {
+  %r = fadd float %x, %x
+  ret float %r
+}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"float-abi", !"hard"}
+; HARD: vadd.f32 s0,
+
+;--- soft.ll
+define float @f(float %x) {
+  %r = fadd float %x, %x
+  ret float %r
+}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"float-abi", !"soft"}
+; SOFT: vmov {{s[0-9]+}}, r0
+
+;--- none.ll
+define float @f(float %x) {
+  %r = fadd float %x, %x
+  ret float %r
+}


        


More information about the llvm-commits mailing list