This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Enable distributive FP optimizations with -ffast-math


The following patch allows GCC to optimize floating point expressions
in combine.c's apply_distributive_law when flag_unsafe_math_optimizations.
This allows us to optimize x*6.0 + y*6.0 into (x+y)*6.0 using -ffast-math
on some platforms.

Whilst I was there I also made two very minor aesthetic changes to tidy
up the surrounding code a bit.  I hope these are acceptable.

The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.

Ok for mainline?


2003-08-23  Roger Sayle  <roger@eyesopen.com>

	* combine.c (apply_distributive_law): Enable "distributive" floating
	point optimizations with -funsafe-math-optimizations.


Index: combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.379
diff -c -3 -p -r1.379 combine.c
*** combine.c	23 Aug 2003 14:46:22 -0000	1.379
--- combine.c	23 Aug 2003 19:16:02 -0000
*************** static rtx
*** 7853,7866 ****
  apply_distributive_law (rtx x)
  {
    enum rtx_code code = GET_CODE (x);
    rtx lhs, rhs, other;
    rtx tem;
-   enum rtx_code inner_code;

!   /* Distributivity is not true for floating point.
!      It can change the value.  So don't do it.
!      -- rms and moshier@world.std.com.  */
!   if (FLOAT_MODE_P (GET_MODE (x)))
      return x;

    /* The outer operation can only be one of the following:  */
--- 7853,7866 ----
  apply_distributive_law (rtx x)
  {
    enum rtx_code code = GET_CODE (x);
+   enum rtx_code inner_code;
    rtx lhs, rhs, other;
    rtx tem;

!   /* Distributivity is not true for floating point as it can change the
!      value.  So we don't do it unless -funsafe-math-optimizations.  */
!   if (FLOAT_MODE_P (GET_MODE (x))
!       && ! flag_unsafe_math_optimizations)
      return x;

    /* The outer operation can only be one of the following:  */
*************** apply_distributive_law (rtx x)
*** 7868,7874 ****
        && code != PLUS && code != MINUS)
      return x;

!   lhs = XEXP (x, 0), rhs = XEXP (x, 1);

    /* If either operand is a primitive we can't do anything, so get out
       fast.  */
--- 7868,7875 ----
        && code != PLUS && code != MINUS)
      return x;

!   lhs = XEXP (x, 0);
!   rhs = XEXP (x, 1);

    /* If either operand is a primitive we can't do anything, so get out
       fast.  */


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]