[llvm] [ARM] Remove `UnsafeFPMath` uses (PR #151275)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 26 01:14:27 PDT 2025
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/151275
>From 59b29962260ba3f933331ab2b6019c8d5848e4dc Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Thu, 31 Jul 2025 16:24:19 +0800
Subject: [PATCH 1/4] Remove UnsafeFPMath uses in ARM
---
llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 21 +++++++++++++++++++--
llvm/test/CodeGen/ARM/neon-spfp.ll | 2 +-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 1c42f44765abf..0666b9e984af9 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -629,6 +629,21 @@ static bool checkDenormalAttributeConsistency(const Module &M,
});
}
+// Returns true if all functions have different denormal modes.
+static bool checkDenormalAttributeInconsistency(const Module &M) {
+ if (M.functions().empty())
+ return false;
+ DenormalMode Value =
+ parseDenormalFPAttribute(M.functions()
+ .begin()
+ ->getFnAttribute("denormal-fp-math")
+ .getValueAsString());
+ return any_of(M, [&](const Function &F) {
+ StringRef AttrVal = F.getFnAttribute("denormal-fp-math").getValueAsString();
+ return parseDenormalFPAttribute(AttrVal) != Value;
+ });
+}
+
void ARMAsmPrinter::emitAttributes() {
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
@@ -695,7 +710,9 @@ void ARMAsmPrinter::emitAttributes() {
DenormalMode::getPositiveZero()))
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
ARMBuildAttrs::PositiveZero);
- else if (!TM.Options.UnsafeFPMath)
+ else if (checkDenormalAttributeInconsistency(*MMI->getModule()) ||
+ checkDenormalAttributeConsistency(
+ *MMI->getModule(), "denormal-fp-math", DenormalMode::getIEEE()))
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
ARMBuildAttrs::IEEEDenormals);
else {
@@ -730,7 +747,7 @@ void ARMAsmPrinter::emitAttributes() {
TM.Options.NoTrappingFPMath)
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
ARMBuildAttrs::Not_Allowed);
- else if (!TM.Options.UnsafeFPMath) {
+ else {
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);
// If the user has permitted this code to choose the IEEE 754
diff --git a/llvm/test/CodeGen/ARM/neon-spfp.ll b/llvm/test/CodeGen/ARM/neon-spfp.ll
index 70a809583ff65..bb6d47b908341 100644
--- a/llvm/test/CodeGen/ARM/neon-spfp.ll
+++ b/llvm/test/CodeGen/ARM/neon-spfp.ll
@@ -7,7 +7,7 @@
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a5 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA5
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a8 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA8
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a9 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA9
-; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a15 --denormal-fp-math=preserve-sign| FileCheck %s -check-prefix=CHECK-UNSAFEA15
+; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a15 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA15
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=swift --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFESWIFT
; RUN: llc < %s -mtriple armv7a-none-darwin -mcpu=cortex-a5 | FileCheck %s -check-prefix=CHECK-DARWINA5
>From 0dc3c9936f30ba100d7fed57032b868574c9d9da Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Wed, 13 Aug 2025 13:15:08 +0800
Subject: [PATCH 2/4] use getDenormalModeRaw
---
llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 0666b9e984af9..edfc53b1d9665 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -633,15 +633,9 @@ static bool checkDenormalAttributeConsistency(const Module &M,
static bool checkDenormalAttributeInconsistency(const Module &M) {
if (M.functions().empty())
return false;
- DenormalMode Value =
- parseDenormalFPAttribute(M.functions()
- .begin()
- ->getFnAttribute("denormal-fp-math")
- .getValueAsString());
- return any_of(M, [&](const Function &F) {
- StringRef AttrVal = F.getFnAttribute("denormal-fp-math").getValueAsString();
- return parseDenormalFPAttribute(AttrVal) != Value;
- });
+ DenormalMode Value = M.functions().begin()->getDenormalModeRaw();
+ return any_of(
+ M, [&](const Function &F) { return F.getDenormalModeRaw() != Value; });
}
void ARMAsmPrinter::emitAttributes() {
>From 8cad2f8b1197800a52c0bb350077513760d0fa0f Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 29 Aug 2025 13:33:31 +0800
Subject: [PATCH 3/4] address comments
---
llvm/test/CodeGen/ARM/neon-spfp.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/ARM/neon-spfp.ll b/llvm/test/CodeGen/ARM/neon-spfp.ll
index bb6d47b908341..70a809583ff65 100644
--- a/llvm/test/CodeGen/ARM/neon-spfp.ll
+++ b/llvm/test/CodeGen/ARM/neon-spfp.ll
@@ -7,7 +7,7 @@
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a5 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA5
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a8 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA8
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a9 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA9
-; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a15 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA15
+; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a15 --denormal-fp-math=preserve-sign| FileCheck %s -check-prefix=CHECK-UNSAFEA15
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=swift --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFESWIFT
; RUN: llc < %s -mtriple armv7a-none-darwin -mcpu=cortex-a5 | FileCheck %s -check-prefix=CHECK-DARWINA5
>From 5a6a193f9a90cf0d7e08cf958dd2ca5241083403 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 26 Sep 2025 16:14:08 +0800
Subject: [PATCH 4/4] Use suggestion and skip declaration
---
llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index edfc53b1d9665..c13d50cdef96b 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -631,11 +631,15 @@ static bool checkDenormalAttributeConsistency(const Module &M,
// Returns true if all functions have different denormal modes.
static bool checkDenormalAttributeInconsistency(const Module &M) {
- if (M.functions().empty())
+ auto F = M.functions().begin();
+ auto E = M.functions().end();
+ if (F == E)
return false;
- DenormalMode Value = M.functions().begin()->getDenormalModeRaw();
- return any_of(
- M, [&](const Function &F) { return F.getDenormalModeRaw() != Value; });
+ DenormalMode Value = F->getDenormalModeRaw();
+ ++F;
+ return std::any_of(F, E, [&](const Function &F) {
+ return !F.isDeclaration() && F.getDenormalModeRaw() != Value;
+ });
}
void ARMAsmPrinter::emitAttributes() {
More information about the llvm-commits
mailing list