From: H.J. Lu Date: Mon, 8 Sep 2025 20:19:45 +0000 (-0700) Subject: x86: Enable SSE4.1 ceil/floor/trunc for -Os X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d1396559e2683c849fb5dba5c8f56f2a4a1ff64;p=thirdparty%2Fgcc.git x86: Enable SSE4.1 ceil/floor/trunc for -Os 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 --- diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 5311d8c4334..5ef7c315091 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -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 index 00000000000..ebd0a57253c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr121861-1a.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -mfpmath=sse -mno-avx -msse4.1" } */ + +#include + +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 index 00000000000..b52faae66d0 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr121861-1b.c @@ -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 } } */