[clang] [Mips] Enable strict fp for Mips in clang (PR #237069)

Ying Huang via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 2 01:15:04 PST 2026


https://github.com/yingopq updated https://github.com/llvm/llvm-project/pull/237069

>From 02c0dc6cbe0652f5d5d24b1b84863a0103e73efa Mon Sep 17 00:00:00 2001
From: Ying Huang <ying.huang at oss.cipunited.com>
Date: Fri, 30 Oct 2026 11:19:14 +0800
Subject: [PATCH 1/3] [Mips] Enable strict fp for Mips in clang

---
 clang/lib/Basic/Targets/Mips.h     | 1 +
 clang/test/CodeGen/Mips/strictfp.c | 7 +++++++
 2 files changed, 8 insertions(+)
 create mode 100644 clang/test/CodeGen/Mips/strictfp.c

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index bb183b825901a3..df310689b1ae5c 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -69,6 +69,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
 
     CanUseBSDABICalls = Triple.isOSFreeBSD() ||
                         Triple.isOSOpenBSD();
+    HasStrictFP = true;
   }
 
   bool isIEEE754_2008Default() const { return ISARev == 6; }
diff --git a/clang/test/CodeGen/Mips/strictfp.c b/clang/test/CodeGen/Mips/strictfp.c
new file mode 100644
index 00000000000000..952df72cbb0207
--- /dev/null
+++ b/clang/test/CodeGen/Mips/strictfp.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple mips64-unknown-linux-gnu -frounding-math \
+// RUN:   -ffp-exception-behavior=strict -emit-llvm -o - %s \
+// RUN:   | FileCheck %s --check-prefixes=STRICT
+//
+// STRICT: call double @llvm.experimental.constrained.fdiv.f64(double 1.000000e+00, double 3.000000e+00, metadata !"round.dynamic", metadata !"fpexcept.strict")
+double div(void) { return 1.0 / 3.0; }
+

>From 44b20fa493c3627b2617603699a3ef348807a625 Mon Sep 17 00:00:00 2001
From: Ying Huang <ying.huang at oss.cipunited.com>
Date: Fri, 30 Oct 2026 15:45:50 +0800
Subject: [PATCH 2/3] Delete no need file and move contents to the new added
 file

---
 clang/test/CodeGen/Mips/strictfp.c |  6 ++++++
 clang/test/CodeGen/fp-strictfp.cpp | 16 ----------------
 2 files changed, 6 insertions(+), 16 deletions(-)
 delete mode 100644 clang/test/CodeGen/fp-strictfp.cpp

diff --git a/clang/test/CodeGen/Mips/strictfp.c b/clang/test/CodeGen/Mips/strictfp.c
index 952df72cbb0207..f7a28e334355a0 100644
--- a/clang/test/CodeGen/Mips/strictfp.c
+++ b/clang/test/CodeGen/Mips/strictfp.c
@@ -5,3 +5,9 @@
 // STRICT: call double @llvm.experimental.constrained.fdiv.f64(double 1.000000e+00, double 3.000000e+00, metadata !"round.dynamic", metadata !"fpexcept.strict")
 double div(void) { return 1.0 / 3.0; }
 
+float fp_precise_1(float a, float b, float c) {
+// STRICT: call float @llvm.experimental.constrained.fmul.f32(float %0, float %1, metadata !"round.dynamic", metadata !"fpexcept.strict")
+// STRICT: call float @llvm.experimental.constrained.fadd.f32(float %mul, float %2, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  return a * b + c;
+}
+
diff --git a/clang/test/CodeGen/fp-strictfp.cpp b/clang/test/CodeGen/fp-strictfp.cpp
deleted file mode 100644
index 124c0f0be29b9c..00000000000000
--- a/clang/test/CodeGen/fp-strictfp.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// RUN: %clang_cc1 -triple mips64-linux-gnu -frounding-math -ffp-exception-behavior=strict -O2 -verify=rounding,exception -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple mips64-linux-gnu -ffp-exception-behavior=strict -O2 -verify=exception -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple mips64-linux-gnu -frounding-math -O2 -verify=rounding -emit-llvm -o - %s | FileCheck %s
-//
-// Verify that constrained intrinsics are not used.
-// As more targets gain support for constrained intrinsics the triple
-// in this test will need to change.
-
-// rounding-warning@* {{overriding currently unsupported rounding mode on this target}}
-// exception-warning@* {{overriding currently unsupported use of floating point exceptions on this target}}
-float fp_precise_1(float a, float b, float c) {
-// CHECK: define{{.*}} float @_Z12fp_precise_1fff
-// CHECK: %[[M:.+]] = fmul float{{.*}}
-// CHECK: fadd float %[[M]], %c
-  return a * b + c;
-}

>From 93960d21b6dfc42fbcdbf5436e8156ffe662654b Mon Sep 17 00:00:00 2001
From: Ying Huang <ying.huang at oss.cipunited.com>
Date: Wed, 2 Dec 2026 17:13:16 +0800
Subject: [PATCH 3/3] [Mips] Enable strict fp for Mips in clang

This enables strict floating-point support for MIPS in Clang by
setting HasStrictFP. The backend support is already in place.
Add a CodeGen test for both N64 and O32, and keep the existing
unsupported-warning test by retargeting it to Hexagon.
---
 clang/test/CodeGen/Mips/strictfp.c |  8 ++++++--
 clang/test/CodeGen/fp-strictfp.cpp | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/fp-strictfp.cpp

diff --git a/clang/test/CodeGen/Mips/strictfp.c b/clang/test/CodeGen/Mips/strictfp.c
index f7a28e334355a0..ef21d157aea621 100644
--- a/clang/test/CodeGen/Mips/strictfp.c
+++ b/clang/test/CodeGen/Mips/strictfp.c
@@ -1,7 +1,11 @@
 // RUN: %clang_cc1 -triple mips64-unknown-linux-gnu -frounding-math \
-// RUN:   -ffp-exception-behavior=strict -emit-llvm -o - %s \
+// RUN:   -ffp-exception-behavior=strict -emit-llvm -o - %s -verify \
 // RUN:   | FileCheck %s --check-prefixes=STRICT
-//
+// RUN: %clang_cc1 -triple mips-unknown-linux-gnu -frounding-math \
+// RUN:   -ffp-exception-behavior=strict -emit-llvm -o - %s -verify \
+// RUN:   | FileCheck %s --check-prefixes=STRICT
+// expected-no-diagnostics
+
 // STRICT: call double @llvm.experimental.constrained.fdiv.f64(double 1.000000e+00, double 3.000000e+00, metadata !"round.dynamic", metadata !"fpexcept.strict")
 double div(void) { return 1.0 / 3.0; }
 
diff --git a/clang/test/CodeGen/fp-strictfp.cpp b/clang/test/CodeGen/fp-strictfp.cpp
new file mode 100644
index 00000000000000..1c46b5e324b9ff
--- /dev/null
+++ b/clang/test/CodeGen/fp-strictfp.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple hexagon-unknown-elf -frounding-math -ffp-exception-behavior=strict -O2 -verify=rounding,exception -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple hexagon-unknown-elf -ffp-exception-behavior=strict -O2 -verify=exception -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple hexagon-unknown-elf -frounding-math -O2 -verify=rounding -emit-llvm -o - %s | FileCheck %s
+//
+// Verify that constrained intrinsics are not used.
+// As more targets gain support for constrained intrinsics the triple
+// in this test will need to change.
+
+// rounding-warning@* {{overriding currently unsupported rounding mode on this target}}
+// exception-warning@* {{overriding currently unsupported use of floating point exceptions on this target}}
+float fp_precise_1(float a, float b, float c) {
+// CHECK: define{{.*}} float @_Z12fp_precise_1fff
+// CHECK: %[[M:.+]] = fmul float{{.*}}
+// CHECK: fadd float %[[M]], %c
+  return a * b + c;
+}



More information about the cfe-commits mailing list