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] for PR 22442


Hello,

chrec_fold_multiply_poly_poly associates chrecs wrongly.  E.g.
(0,+,1) * (0,+,1) = (0,+,(1,+,2)), but we currently return
((0,+,1),+,2) -- equal to (0,+,3).

Bootstrapped & regtested on i686.

Zdenek

	PR tree-optimization/22442
	* tree-chrec.c (chrec_fold_multiply_poly_poly): Associate chrecs
	correctly.

Index: tree-chrec.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-chrec.c,v
retrieving revision 2.21
diff -c -3 -p -r2.21 tree-chrec.c
*** tree-chrec.c	25 Jun 2005 02:01:15 -0000	2.21
--- tree-chrec.c	12 Jul 2005 15:11:08 -0000
*************** chrec_fold_multiply_poly_poly (tree type
*** 167,172 ****
--- 167,175 ----
  			       tree poly0, 
  			       tree poly1)
  {
+   tree t0, t1, t2;
+   int var;
+ 
    gcc_assert (poly0);
    gcc_assert (poly1);
    gcc_assert (TREE_CODE (poly0) == POLYNOMIAL_CHREC);
*************** chrec_fold_multiply_poly_poly (tree type
*** 191,218 ****
    
    /* poly0 and poly1 are two polynomials in the same variable,
       {a, +, b}_x * {c, +, d}_x  ->  {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x.  */
!   return 
!     build_polynomial_chrec 
!     (CHREC_VARIABLE (poly0), 
!      build_polynomial_chrec 
!      (CHREC_VARIABLE (poly0), 
!       
!       /* "a*c".  */
!       chrec_fold_multiply (type, CHREC_LEFT (poly0), CHREC_LEFT (poly1)),
!       
!       /* "a*d + b*c + b*d".  */
!       chrec_fold_plus 
!       (type, chrec_fold_multiply (type, CHREC_LEFT (poly0), CHREC_RIGHT (poly1)),
!        
!        chrec_fold_plus 
!        (type, 
! 	chrec_fold_multiply (type, CHREC_RIGHT (poly0), CHREC_LEFT (poly1)),
! 	chrec_fold_multiply (type, CHREC_RIGHT (poly0), CHREC_RIGHT (poly1))))),
!      
!      /* "2*b*d".  */
!      chrec_fold_multiply
!      (type, build_int_cst (NULL_TREE, 2),
!       chrec_fold_multiply (type, CHREC_RIGHT (poly0), CHREC_RIGHT (poly1))));
  }
  
  /* When the operands are automatically_generated_chrec_p, the fold has
--- 194,218 ----
    
    /* poly0 and poly1 are two polynomials in the same variable,
       {a, +, b}_x * {c, +, d}_x  ->  {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x.  */
!       
!   /* "a*c".  */
!   t0 = chrec_fold_multiply (type, CHREC_LEFT (poly0), CHREC_LEFT (poly1));
! 
!   /* "a*d + b*c + b*d".  */
!   t1 = chrec_fold_multiply (type, CHREC_LEFT (poly0), CHREC_RIGHT (poly1));
!   t1 = chrec_fold_plus (type, t1, chrec_fold_multiply (type,
! 						       CHREC_RIGHT (poly0),
! 						       CHREC_LEFT (poly1)));
!   t1 = chrec_fold_plus (type, t1, chrec_fold_multiply (type,
! 						       CHREC_RIGHT (poly0),
! 						       CHREC_RIGHT (poly1)));
!   /* "2*b*d".  */
!   t2 = chrec_fold_multiply (type, CHREC_RIGHT (poly0), CHREC_RIGHT (poly1));
!   t2 = chrec_fold_multiply (type, build_int_cst_type (type, 2), t2);
! 
!   var = CHREC_VARIABLE (poly0);
!   return build_polynomial_chrec (var, t0,
! 				 build_polynomial_chrec (var, t1, t2));
  }
  
  /* When the operands are automatically_generated_chrec_p, the fold has


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