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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 02:37:31 PDT 2026


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/212981

>From fbaa1126e6b47bb6e5b4578253f11565b3090049 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 20 Jul 2026 14:17:24 +0200
Subject: [PATCH 1/2] ARM: Read float ABI from the "float-abi" module flag

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>
---
 llvm/lib/Target/ARM/ARMAsmPrinter.cpp         |  7 ++-
 llvm/lib/Target/ARM/ARMTargetMachine.cpp      | 11 ++++-
 .../test/CodeGen/ARM/float-abi-module-flag.ll | 43 +++++++++++++++++++
 3 files changed, 59 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/ARM/float-abi-module-flag.ll

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..c484ffcdb395f
--- /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 module flag overrides the target-default soft ABI even without -float-abi.
+; 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
+}

>From 848e5639ccf5a70f501265e14ebd3045be5e053d Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 12 Aug 2026 11:36:52 +0200
Subject: [PATCH 2/2] Fix test comment

---
 llvm/test/CodeGen/ARM/float-abi-module-flag.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/ARM/float-abi-module-flag.ll b/llvm/test/CodeGen/ARM/float-abi-module-flag.ll
index c484ffcdb395f..ea57078c619bd 100644
--- a/llvm/test/CodeGen/ARM/float-abi-module-flag.ll
+++ b/llvm/test/CodeGen/ARM/float-abi-module-flag.ll
@@ -11,7 +11,7 @@
 ; 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 module flag overrides the target-default soft ABI even without -float-abi.
+; 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.



More information about the llvm-commits mailing list