Patchwork Fix reassoc ICE (PR tree-optimization/56559)

login
register
mail settings
Submitter Jakub Jelinek
Date March 7, 2013, 1:49 p.m.
Message ID <20130307134909.GB12913@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/225856/
State New
Headers show

Comments

Jakub Jelinek - March 7, 2013, 1:49 p.m.
Hi!

During zero_one_operation I believe we can count in the chain having single
uses if we go through rhs1s, but the change from last year also added
looking through rhs2, and there I don't see anything that would guarantee
a single use, and the following testcase shows where it has two uses.

If it has more than one use, obviously we can't change the pow call just
because in one of the uses we'd like to remove one multiplication.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-03-07  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/56559
	* tree-ssa-reassoc.c (zero_one_operation): When looking at rhs2,
	check that it has only a single use.

	* gcc.dg/tree-ssa/reassoc-26.c: New test.


	Jakub
Richard Guenther - March 7, 2013, 2:31 p.m.
On Thu, 7 Mar 2013, Jakub Jelinek wrote:

> Hi!
> 
> During zero_one_operation I believe we can count in the chain having single
> uses if we go through rhs1s, but the change from last year also added
> looking through rhs2, and there I don't see anything that would guarantee
> a single use, and the following testcase shows where it has two uses.
> 
> If it has more than one use, obviously we can't change the pow call just
> because in one of the uses we'd like to remove one multiplication.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2013-03-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/56559
> 	* tree-ssa-reassoc.c (zero_one_operation): When looking at rhs2,
> 	check that it has only a single use.
> 
> 	* gcc.dg/tree-ssa/reassoc-26.c: New test.
> 
> --- gcc/tree-ssa-reassoc.c.jj	2013-02-18 16:39:55.000000000 +0100
> +++ gcc/tree-ssa-reassoc.c	2013-03-07 10:09:22.048925800 +0100
> @@ -1107,7 +1107,8 @@ zero_one_operation (tree *def, enum tree
>  	 the operand might be hiding in the rightmost one.  */
>        if (opcode == MULT_EXPR
>  	  && gimple_assign_rhs_code (stmt) == opcode
> -	  && TREE_CODE (gimple_assign_rhs2 (stmt)) == SSA_NAME)
> +	  && TREE_CODE (gimple_assign_rhs2 (stmt)) == SSA_NAME
> +	  && has_single_use (gimple_assign_rhs2 (stmt)))
>  	{
>  	  gimple stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs2 (stmt));
>  	  if (stmt_is_power_of_op (stmt2, op))
> --- gcc/testsuite/gcc.dg/tree-ssa/reassoc-26.c.jj	2013-03-07 10:10:49.400749110 +0100
> +++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-26.c	2013-03-07 10:10:18.000000000 +0100
> @@ -0,0 +1,12 @@
> +/* PR tree-optimization/56559 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -ffast-math" } */
> +
> +double a, b, c, d, e;
> +
> +void
> +foo ()
> +{
> +  a = e * e;
> +  b = d * e + c * e * a;
> +}
> 
> 	Jakub
> 
>

Patch

--- gcc/tree-ssa-reassoc.c.jj	2013-02-18 16:39:55.000000000 +0100
+++ gcc/tree-ssa-reassoc.c	2013-03-07 10:09:22.048925800 +0100
@@ -1107,7 +1107,8 @@  zero_one_operation (tree *def, enum tree
 	 the operand might be hiding in the rightmost one.  */
       if (opcode == MULT_EXPR
 	  && gimple_assign_rhs_code (stmt) == opcode
-	  && TREE_CODE (gimple_assign_rhs2 (stmt)) == SSA_NAME)
+	  && TREE_CODE (gimple_assign_rhs2 (stmt)) == SSA_NAME
+	  && has_single_use (gimple_assign_rhs2 (stmt)))
 	{
 	  gimple stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs2 (stmt));
 	  if (stmt_is_power_of_op (stmt2, op))
--- gcc/testsuite/gcc.dg/tree-ssa/reassoc-26.c.jj	2013-03-07 10:10:49.400749110 +0100
+++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-26.c	2013-03-07 10:10:18.000000000 +0100
@@ -0,0 +1,12 @@ 
+/* PR tree-optimization/56559 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math" } */
+
+double a, b, c, d, e;
+
+void
+foo ()
+{
+  a = e * e;
+  b = d * e + c * e * a;
+}