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  <ja...@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

Reply via email to