[llvm] [Mips] Fix wrong ELF FP ABI info when inline asm was empty (PR #146457)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 20:08:57 PDT 2025


https://github.com/yingopq created https://github.com/llvm/llvm-project/pull/146457

When Mips process emitStartOfAsmFile and updateABIInfo, it did not know the real value of IsSoftFloat and STI.useSoftFloat(). And when inline asm instruction was empty, Mips did not process asm parser, so it would not do TS.updateABIInfo(STI) again and at this time the value of IsSoftFloat is correct.

Fix #135283.

>From 89af001e9ced82e41817f9d7f1d7020c88c5e02c Mon Sep 17 00:00:00 2001
From: Ying Huang <ying.huang at oss.cipunited.com>
Date: Mon, 30 Jun 2025 22:48:04 -0400
Subject: [PATCH] [Mips] Fix wrong ELF FP ABI info when inline asm was empty

When Mips process emitStartOfAsmFile and updateABIInfo, it did not
know the real value of IsSoftFloat and STI.useSoftFloat(). And when
inline asm instruction was empty, Mips did not process asm parser,
so it would not do TS.updateABIInfo(STI) again and at this time the
value of IsSoftFloat is correct.

Fix #135283.
---
 llvm/lib/Target/Mips/MipsAsmPrinter.cpp       |  8 ++++++--
 llvm/test/CodeGen/Mips/abiflags-soft-float.ll | 12 ++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/abiflags-soft-float.ll

diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 1a3e99ec7f68f..cb2ac3000b717 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -745,14 +745,18 @@ void MipsAsmPrinter::emitStartOfAsmFile(Module &M) {
     if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
       FS = F->getFnAttribute("target-features").getValueAsString();
 
+    std::string strFS = FS.str();
+    if (M.size() && F->getFnAttribute("use-soft-float").getValueAsBool())
+      strFS += strFS.empty() ? "+soft-float" : ",+soft-float";
+
     // Compute MIPS architecture attributes based on the default subtarget
     // that we'd have constructed.
     // FIXME: For ifunc related functions we could iterate over and look
     // for a feature string that doesn't match the default one.
     StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
     const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
-    const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM,
-                            std::nullopt);
+    const MipsSubtarget STI(TT, CPU, StringRef(strFS), MTM.isLittleEndian(),
+                            MTM, std::nullopt);
 
     bool IsABICalls = STI.isABICalls();
     const MipsABIInfo &ABI = MTM.getABI();
diff --git a/llvm/test/CodeGen/Mips/abiflags-soft-float.ll b/llvm/test/CodeGen/Mips/abiflags-soft-float.ll
new file mode 100644
index 0000000000000..01821f2d9b6c6
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/abiflags-soft-float.ll
@@ -0,0 +1,12 @@
+; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips32 %s -o tmp.o
+; RUN: llvm-readobj -A tmp.o | FileCheck %s -check-prefix=OBJ
+; RUN: llc -filetype=asm -mtriple mipsel-unknown-linux -mcpu=mips32 %s -o - | \
+; RUN: FileCheck %s -check-prefix=ASM
+
+; OBJ: FP ABI: Soft float
+; ASM: .module	softfloat 
+
+define dso_local void @asm_is_null() "use-soft-float"="true" {
+  call void asm sideeffect "", ""()
+  ret void
+}



More information about the llvm-commits mailing list