Hi!

As has been mentioned earlier, when the doloop code uses the expander after
expansion, we need to unshare stuff because the expander relies on unsharing
being done after it.

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

2017-06-02  Jakub Jelinek  <ja...@redhat.com>

        PR rtl-optimization/80903
        * loop-doloop.c (add_test): Unshare sequence.

        * gcc.dg/pr80903.c: New test.

--- gcc/loop-doloop.c.jj        2017-03-24 14:36:35.000000000 +0100
+++ gcc/loop-doloop.c   2017-05-29 12:40:39.062107631 +0200
@@ -367,6 +367,7 @@ add_test (rtx cond, edge *e, basic_block
     }
 
   seq = get_insns ();
+  unshare_all_rtl_in_chain (seq);
   end_sequence ();
 
   /* There always is at least the jump insn in the sequence.  */
--- gcc/testsuite/gcc.dg/pr80903.c.jj   2017-05-29 12:40:27.988242239 +0200
+++ gcc/testsuite/gcc.dg/pr80903.c      2017-05-29 12:37:39.000000000 +0200
@@ -0,0 +1,34 @@
+/* PR rtl-optimization/80903 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -funroll-loops" } */
+
+short int a;
+
+void
+foo (int x, short int y, short int z)
+{
+  if (y != 0)
+    {
+      const short int b = 37;
+      y = 0;
+      while (y < b)
+       {
+         while (y < b)
+           {
+           lab:
+             ++y;
+           }
+         for (y = 0; y < b - 1; ++y)
+           ;
+         if (z != 0)
+           {
+             --a;
+             y *= a;
+           }
+         z = x;
+       }
+      x = 0;
+    }
+
+  goto lab;
+}

        Jakub

Reply via email to