diff mbox

Fix RTL sharing bug in loop unswitching (PR rtl-optimization/52092)

Message ID 20120202191227.GA18768@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 2, 2012, 7:12 p.m. UTC
Hi!

It seems loop-iv.c happily creates shared RTL in lots of places,
loop-unroll.c solves that by unsharing everything it adds, this is
an attempt to do the same in unswitching to unshare everything iv_analyze
came up with.

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

2012-02-02  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/52092
	* loop-unswitch.c (may_unswitch_on): Call copy_rtx_if_shared
	on get_iv_value result.

	* gcc.c-torture/compile/pr52092.c: New test.


	Jakub

Comments

Zdenek Dvorak Feb. 3, 2012, 8:17 a.m. UTC | #1
Hi,

> It seems loop-iv.c happily creates shared RTL in lots of places,
> loop-unroll.c solves that by unsharing everything it adds, this is
> an attempt to do the same in unswitching to unshare everything iv_analyze
> came up with.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

I would suggest to move the unsharing to the point where it is clear that
the rtl will added, i.e.,

loop-unswitch.c:370
  nloop = unswitch_loop (loop, bbs[i], cond, cinsn);
->
  nloop = unswitch_loop (loop, bbs[i], copy_rtx_if_shared (cond), cinsn);

Zdenek
Richard Biener Feb. 3, 2012, 9:33 a.m. UTC | #2
On Thu, 2 Feb 2012, Jakub Jelinek wrote:

> Hi!
> 
> It seems loop-iv.c happily creates shared RTL in lots of places,
> loop-unroll.c solves that by unsharing everything it adds, this is
> an attempt to do the same in unswitching to unshare everything iv_analyze
> came up with.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2012-02-02  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR rtl-optimization/52092
> 	* loop-unswitch.c (may_unswitch_on): Call copy_rtx_if_shared
> 	on get_iv_value result.
> 
> 	* gcc.c-torture/compile/pr52092.c: New test.
> 
> --- gcc/loop-unswitch.c.jj	2010-06-28 15:36:30.000000000 +0200
> +++ gcc/loop-unswitch.c	2012-02-02 14:00:55.127749909 +0100
> @@ -204,6 +204,7 @@ may_unswitch_on (basic_block bb, struct
>  	return NULL_RTX;
>  
>        op[i] = get_iv_value (&iv, const0_rtx);
> +      op[i] = copy_rtx_if_shared (op[i]);
>      }
>  
>    mode = GET_MODE (op[0]);
> --- gcc/testsuite/gcc.c-torture/compile/pr52092.c.jj	2012-02-02 14:11:37.722031008 +0100
> +++ gcc/testsuite/gcc.c-torture/compile/pr52092.c	2012-02-02 14:11:14.000000000 +0100
> @@ -0,0 +1,25 @@
> +/* PR rtl-optimization/52092 */
> +
> +int a, b, c, d, e, f, g;
> +
> +void
> +foo (void)
> +{
> +  for (;;)
> +    {
> +      int *h = 0;
> +      int i = 3;
> +      int **j = &h;
> +      if (e)
> +	{
> +	  c = d || a;
> +	  g = c ? a : b;
> +	  if ((char) (i * g))
> +	    {
> +	      h = &f;
> +	      *h = 0;
> +	    }
> +	  **j = 0;
> +	}
> +    }
> +}
> 
> 	Jakub
> 
>
diff mbox

Patch

--- gcc/loop-unswitch.c.jj	2010-06-28 15:36:30.000000000 +0200
+++ gcc/loop-unswitch.c	2012-02-02 14:00:55.127749909 +0100
@@ -204,6 +204,7 @@  may_unswitch_on (basic_block bb, struct
 	return NULL_RTX;
 
       op[i] = get_iv_value (&iv, const0_rtx);
+      op[i] = copy_rtx_if_shared (op[i]);
     }
 
   mode = GET_MODE (op[0]);
--- gcc/testsuite/gcc.c-torture/compile/pr52092.c.jj	2012-02-02 14:11:37.722031008 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr52092.c	2012-02-02 14:11:14.000000000 +0100
@@ -0,0 +1,25 @@ 
+/* PR rtl-optimization/52092 */
+
+int a, b, c, d, e, f, g;
+
+void
+foo (void)
+{
+  for (;;)
+    {
+      int *h = 0;
+      int i = 3;
+      int **j = &h;
+      if (e)
+	{
+	  c = d || a;
+	  g = c ? a : b;
+	  if ((char) (i * g))
+	    {
+	      h = &f;
+	      *h = 0;
+	    }
+	  **j = 0;
+	}
+    }
+}