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] Fix PR39937, wrong types from distribute_real_division


416.gamess fails to build because distribute_real_division
looses sign-changes.  The fix is to only use distribute_real_division
on floating point types.  I verified the corresponding (but correct)
transformation is done for integers elsewhere.

Bootstrap / regtest ongoing on x86_64-unknown-linux-gnu, I'll apply
this after it succeeded.

Richard.

2009-04-28  Richard Guenther  <rguenther@suse.de>

	PR middle-end/39937
	* fold-const.c (fold_binary): Use distribute_real_division only
	on float types.

	* gfortran.fortran-torture/compile/pr39937.f: New testcase.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 146887)
--- gcc/fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 10100,10112 ****
  		      return fold_build2 (COMPLEX_EXPR, type, rp, ip);
  		    }
  		}
- 	    }
  
!           if (flag_unsafe_math_optimizations
! 	      && (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR)
! 	      && (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR)
! 	      && (tem = distribute_real_division (code, type, arg0, arg1)))
! 	    return tem;
  
  	  /* Convert x+x into x*2.0.  */
  	  if (operand_equal_p (arg0, arg1, 0)
--- 10100,10114 ----
  		      return fold_build2 (COMPLEX_EXPR, type, rp, ip);
  		    }
  		}
  
! 	      if (flag_unsafe_math_optimizations
! 		  && (TREE_CODE (arg0) == RDIV_EXPR
! 		      || TREE_CODE (arg0) == MULT_EXPR)
! 		  && (TREE_CODE (arg1) == RDIV_EXPR
! 		      || TREE_CODE (arg1) == MULT_EXPR)
! 		  && (tem = distribute_real_division (code, type, arg0, arg1)))
! 		return tem;
! 	    }
  
  	  /* Convert x+x into x*2.0.  */
  	  if (operand_equal_p (arg0, arg1, 0)
*************** fold_binary (enum tree_code code, tree t
*** 10540,10552 ****
  			          fold_convert (type, esz));
  			          
  	    }
- 	}
  
!       if (flag_unsafe_math_optimizations
! 	  && (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR)
! 	  && (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR)
! 	  && (tem = distribute_real_division (code, type, arg0, arg1)))
! 	return tem;
  
        /* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the
  	 same or one.  Make sure type is not saturating.
--- 10542,10556 ----
  			          fold_convert (type, esz));
  			          
  	    }
  
! 	  if (flag_unsafe_math_optimizations
! 	      && (TREE_CODE (arg0) == RDIV_EXPR
! 		  || TREE_CODE (arg0) == MULT_EXPR)
! 	      && (TREE_CODE (arg1) == RDIV_EXPR
! 		  || TREE_CODE (arg1) == MULT_EXPR)
! 	      && (tem = distribute_real_division (code, type, arg0, arg1)))
! 	    return tem;
! 	}
  
        /* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the
  	 same or one.  Make sure type is not saturating.
Index: gcc/testsuite/gfortran.fortran-torture/compile/pr39937.f
===================================================================
*** gcc/testsuite/gfortran.fortran-torture/compile/pr39937.f	(revision 0)
--- gcc/testsuite/gfortran.fortran-torture/compile/pr39937.f	(revision 0)
***************
*** 0 ****
--- 1,28 ----
+       SUBROUTINE DTREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR,
+      $                   LDVR, MM, M, WORK, INFO )
+       DOUBLE PRECISION   T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
+      $                   WORK( * )
+       DOUBLE PRECISION   X( 2, 2 )
+       CALL DLALN2( .FALSE., 1, 1, SMIN, ONE, T( J, J ),
+      $                            ZERO, X, 2, SCALE, XNORM, IERR )
+       CALL DSCAL( KI, SCALE, WORK( 1+N ), 1 )
+       DO 90 J = KI - 2, 1, -1
+       IF( J.GT.JNXT )
+      $               GO TO 90
+       JNXT = J - 1
+       IF( J.GT.1 ) THEN
+           IF( T( J, J-1 ).NE.ZERO ) THEN
+               IF( WORK( J ).GT.BIGNUM / XNORM ) THEN
+                   X( 1, 1 ) = X( 1, 1 ) / XNORM
+               END IF
+           END IF
+           CALL DLALN2( .FALSE., 2, 2, SMIN, ONE,
+      $                            T( J-1, J-1 ), LDT, ONE, ONE,
+      $                            XNORM, IERR )
+           CALL DAXPY( J-2, -X( 1, 1 ), T( 1, J-1 ), 1,
+      $                           WORK( 1+N ), 1 )
+           CALL DAXPY( J-2, -X( 2, 2 ), T( 1, J ), 1,
+      $                           WORK( 1+N2 ), 1 )
+       END IF
+    90          CONTINUE
+       END


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