diff mbox

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

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

Commit Message

Jakub Jelinek Feb. 3, 2012, 12:01 p.m. UTC
On Fri, Feb 03, 2012 at 09:17:23AM +0100, Zdenek Dvorak wrote:
> > 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);

You're right, and that also cures the thing that inner unswitch_single_loop
might use again a condition based on the same rtl (or reverse_condition
thereof).  Bootstrapped/regtested again on x86_64-linux and i686-linux,
approved by Richard on IRC, committed to trunk.  Thanks.

2012-02-03  Jakub Jelinek  <jakub@redhat.com>
	    Zdenek Dvorak  <ook@ucw.cz>

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

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


	Jakub
diff mbox

Patch

--- gcc/loop-unswitch.c.jj	2010-06-28 15:36:30.000000000 +0200
+++ gcc/loop-unswitch.c	2012-02-03 09:24:24.385450397 +0100
@@ -367,7 +367,7 @@  unswitch_single_loop (struct loop *loop,
     fprintf (dump_file, ";; Unswitching loop\n");
 
   /* Unswitch the loop on this condition.  */
-  nloop = unswitch_loop (loop, bbs[i], cond, cinsn);
+  nloop = unswitch_loop (loop, bbs[i], copy_rtx_if_shared (cond), cinsn);
   gcc_assert (nloop);
 
   /* Invoke itself on modified loops.  */
--- 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;
+	}
+    }
+}