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 PR28162, ICE on valid code, wrong types in fold


This fixes PR28162 by converting the intermediate results to the
correct type.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline?  (and branch?  The bug is latent there.)

Thanks,
Richard.

:ADDPATCH middle-end:

2006-07-04  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/28162
	* fold-const.c (fold_binary): For (-A) * (-B) -> A * B
	make sure to convert the operands to the correct type.

	* gcc.dg/pr28162.c: New testcase.

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 115175)
--- fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 8852,8863 ****
        /* (-A) * (-B) -> A * B  */
        if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
  	return fold_build2 (MULT_EXPR, type,
! 			    TREE_OPERAND (arg0, 0),
! 			    negate_expr (arg1));
        if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
  	return fold_build2 (MULT_EXPR, type,
! 			    negate_expr (arg0),
! 			    TREE_OPERAND (arg1, 0));
  
        if (! FLOAT_TYPE_P (type))
  	{
--- 8852,8863 ----
        /* (-A) * (-B) -> A * B  */
        if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
  	return fold_build2 (MULT_EXPR, type,
! 			    fold_convert (type, TREE_OPERAND (arg0, 0)),
! 			    fold_convert (type, negate_expr (arg1)));
        if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
  	return fold_build2 (MULT_EXPR, type,
! 			    fold_convert (type, negate_expr (arg0)),
! 			    fold_convert (type, TREE_OPERAND (arg1, 0)));
  
        if (! FLOAT_TYPE_P (type))
  	{
Index: testsuite/gcc.dg/pr28162.c
===================================================================
*** testsuite/gcc.dg/pr28162.c	(revision 0)
--- testsuite/gcc.dg/pr28162.c	(revision 0)
***************
*** 0 ****
--- 1,17 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O3" } */
+ 
+ void Lag_max_wght(float corr[], long wght_flg)
+ {
+      float t0, max;
+      const float *ww;
+      long i;
+      if ( wght_flg > 0 ) {
+         for ( i = 143; i >= 20; i-- ) {
+            t0 = corr[ - i] * *ww--;
+            if ( t0 >= max )
+              max = t0;
+         }
+      }
+ }
+ 


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