]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
x86: Enable SSE4.1 ceil/floor/trunc for -Os
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 8 Sep 2025 20:19:45 +0000 (13:19 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 9 Sep 2025 03:22:05 +0000 (20:22 -0700)
Enable SSE4.1 ceil/floor/trunc for -Os to replace a function call with
roundss or roundsd by dropping the !flag_trapping_math check.

gcc/

PR target/121861
* config/i386/i386.cc (ix86_optab_supported_p): Drop
!flag_trapping_math check for floor_optab, ceil_optab and
btrunc_optab.

gcc/testsuite/

PR target/121861
* gcc.target/i386/pr121861-1a.c: New file.
* gcc.target/i386/pr121861-1b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
gcc/config/i386/i386.cc
gcc/testsuite/gcc.target/i386/pr121861-1a.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr121861-1b.c [new file with mode: 0644]

index 5311d8c433427d3032dff6f6a6a869538a9ffa66..5ef7c315091db68c415a7cf8e0264c95cdd3a77a 100644 (file)
@@ -27250,11 +27250,10 @@ ix86_optab_supported_p (int op, machine_mode mode1, machine_mode,
     case floor_optab:
     case ceil_optab:
     case btrunc_optab:
-      if (((SSE_FLOAT_MODE_P (mode1)
-           && TARGET_SSE_MATH
-           && TARGET_SSE4_1)
-          || mode1 == HFmode)
-         && !flag_trapping_math)
+      if ((SSE_FLOAT_MODE_P (mode1)
+          && TARGET_SSE_MATH
+          && TARGET_SSE4_1)
+         || mode1 == HFmode)
        return true;
       return opt_type == OPTIMIZE_FOR_SPEED;
 
diff --git a/gcc/testsuite/gcc.target/i386/pr121861-1a.c b/gcc/testsuite/gcc.target/i386/pr121861-1a.c
new file mode 100644 (file)
index 0000000..ebd0a57
--- /dev/null
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -mfpmath=sse -mno-avx -msse4.1" } */
+
+#include <math.h>
+
+float
+cf (float x)
+{
+  return ceilf (x);
+}
+
+float
+ff (float x)
+{
+  return floorf (x);
+}
+
+float
+tf (float x)
+{
+  return truncf (x);
+}
+
+double
+c (double x)
+{
+  return ceil (x);
+}
+
+double
+f (double x)
+{
+  return floor (x);
+}
+
+double
+t (double x)
+{
+  return trunc (x);
+}
+
+/* { dg-final { scan-assembler-times "roundss" 3 } } */
+/* { dg-final { scan-assembler-times "roundsd" 3 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr121861-1b.c b/gcc/testsuite/gcc.target/i386/pr121861-1b.c
new file mode 100644 (file)
index 0000000..b52faae
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -mfpmath=sse -mno-avx512f -mavx" } */
+
+#include "pr121861-1a.c"
+
+/* { dg-final { scan-assembler-times "vroundss" 3 } } */
+/* { dg-final { scan-assembler-times "vroundsd" 3 } } */