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

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jul 30 02:58:26 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-arm

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>

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@<!-- -->anthropic.com>

---
Full diff: https://github.com/llvm/llvm-project/pull/212981.diff


3 Files Affected:

- (modified) llvm/lib/Target/ARM/ARMAsmPrinter.cpp (+6-1) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.cpp (+10-1) 
- (added) llvm/test/CodeGen/ARM/float-abi-module-flag.ll (+43) 


``````````diff
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 e31c578720fa1..5f7d12dcc3a5a 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"
@@ -227,7 +228,15 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
   if (SoftFloat)
     FS += FS.empty() ? "+soft-float" : ",+soft-float";
 
-  FloatABI::ABIType FloatABI = 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");
+  }
 
   // Use the optminsize to identify the subtarget, but don't use it in the
   // feature string.
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
+}

``````````

</details>


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


More information about the llvm-branch-commits mailing list