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>
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;
--- /dev/null
+/* { 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 } } */
--- /dev/null
+/* { 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 } } */