associative law in combine

Toon Moene toon@moene.indiv.nluug.nl
Tue Jul 17 11:02:00 GMT 2001


Jan Hubicka wrote:

> for some purpose combine attempts to apply associative law even on
> divisions.  Unless I am totally confused today, it is wrong.
> I've failed to construct testcase to produce incorrect assembly tought.
> 
> Patch also enables the associative law for floating point values in
> -ffast-math mode, that should be safe too I hope.

You are right that division is not associative when applied to integers,
but, given -ffast-math mode, it *is* allowed to change X/A/B into
X/(A*B).

Patch attached - I'll bootstrap it on i686-pc-linux-gnu tonight.

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
2001-07-17  Toon Moene  <toon@moene.indiv.nluug.nl>

	* combine.c (combine_simplify_rtx): DIV can be treated
	associatively for floats if unsafe math optimisations are enabled.

*** combine.c.orig	Tue Jul 17 17:27:59 2001
--- combine.c	Tue Jul 17 19:06:43 2001
*************** combine_simplify_rtx (x, op0_mode, last,
*** 3722,3731 ****
    /* If CODE is an associative operation not otherwise handled, see if we
       can associate some operands.  This can win if they are constants or
       if they are logically related (i.e. (a & b) & a).  */
!   if ((code == PLUS || code == MINUS
!        || code == MULT || code == AND || code == IOR || code == XOR
         || code == SMAX || code == SMIN || code == UMAX || code == UMIN)
!       && (INTEGRAL_MODE_P (mode)
  	  || (flag_unsafe_math_optimizations && FLOAT_MODE_P (mode))))
      {
        if (GET_CODE (XEXP (x, 0)) == code)
--- 3722,3731 ----
    /* If CODE is an associative operation not otherwise handled, see if we
       can associate some operands.  This can win if they are constants or
       if they are logically related (i.e. (a & b) & a).  */
!   if ((code == PLUS || code == MINUS || code == MULT || code == DIV
!        || code == AND || code == IOR || code == XOR
         || code == SMAX || code == SMIN || code == UMAX || code == UMIN)
!       && ((INTEGRAL_MODE_P (mode) && code != DIV)
  	  || (flag_unsafe_math_optimizations && FLOAT_MODE_P (mode))))
      {
        if (GET_CODE (XEXP (x, 0)) == code)
*************** combine_simplify_rtx (x, op0_mode, last,
*** 3745,3751 ****
  	    }
  	  inner = simplify_binary_operation (code == MINUS ? PLUS
  					     : code == DIV ? MULT
- 					     : code == UDIV ? MULT
  					     : code,
  					     mode, inner_op0, inner_op1);
  
--- 3745,3750 ----


More information about the Gcc-patches mailing list