re PR tree-optimization/22442 (scev cprop causes wrong code)

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

From-SVN: r101962
This commit is contained in:
Zdenek Dvorak 2005-07-13 12:08:36 +02:00 committed by Zdenek Dvorak
parent 7869fe47b3
commit 2c5f025d8d
2 changed files with 27 additions and 21 deletions

View File

@ -1,3 +1,9 @@
2005-07-12 Zdenek Dvorak <dvorakz@suse.cz>
PR tree-optimization/22442
* tree-chrec.c (chrec_fold_multiply_poly_poly): Associate chrecs
correctly.
2005-07-12 Zdenek Dvorak <dvorakz@suse.cz>
PR rtl-optimization/20376

View File

@ -167,6 +167,9 @@ chrec_fold_multiply_poly_poly (tree type,
tree poly0,
tree poly1)
{
tree t0, t1, t2;
int var;
gcc_assert (poly0);
gcc_assert (poly1);
gcc_assert (TREE_CODE (poly0) == POLYNOMIAL_CHREC);
@ -191,28 +194,25 @@ chrec_fold_multiply_poly_poly (tree type,
/* 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))));
/* "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