re PR middle-end/70359 (Code size increase for x86/ARM/others compared to gcc-5.3.0)
authorRichard Biener <rguenther@suse.de>
Wed, 31 Oct 2018 11:57:33 +0000 (11:57 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 31 Oct 2018 11:57:33 +0000 (11:57 +0000)
2018-10-31  Richard Biener  <rguenther@suse.de>

PR middle-end/70359
PR middle-end/86270
* tree-outof-ssa.c (insert_backedge_copies): Restrict
copy generation to useful cases.  Place the copy before
the definition of the backedge value when possible.

* gcc.target/i386/pr70359.c: New testcase.
* gcc.target/i386/pr86270.c: Likewise.

From-SVN: r265677

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr70359.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr86270.c [new file with mode: 0644]
gcc/tree-outof-ssa.c

index 289bb5a..1f45354 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-31  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/70359
+       PR middle-end/86270
+       * tree-outof-ssa.c (insert_backedge_copies): Restrict
+       copy generation to useful cases.  Place the copy before
+       the definition of the backedge value when possible.
+
 2018-10-31  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * config/arc/arc-arch.h (ARC_TUNE_ARC7XX): New tune value.
index f2a4a8d..8492316 100644 (file)
@@ -1,3 +1,10 @@
+2018-10-31  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/70359
+       PR middle-end/86270
+       * gcc.target/i386/pr70359.c: New testcase.
+       * gcc.target/i386/pr86270.c: Likewise.
+
 2018-10-31  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * gcc.target/arc/jumptable.c: New test.
diff --git a/gcc/testsuite/gcc.target/i386/pr70359.c b/gcc/testsuite/gcc.target/i386/pr70359.c
new file mode 100644 (file)
index 0000000..85b7017
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+char* inttostr(int i, char* buf, int len)
+{
+  unsigned int ui = (i > 0) ? i : -i;
+  char *p = buf + len - 1;
+  *p = '\0';
+  do {
+    *--p = '0' + (ui % 10);
+  } while ((ui /= 10) != 0);
+  if (i < 0) {
+    *--p = '-';
+  }
+  return p;
+}
+
+/* In out-of-SSA we should have avoided splitting the latch edge of the
+   loop by inserting copies.  */
+/* { dg-final { scan-assembler-times "L\[0-9\]+:" 2 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr86270.c b/gcc/testsuite/gcc.target/i386/pr86270.c
new file mode 100644 (file)
index 0000000..81841ef
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int *a;
+long len;
+
+int
+test ()
+{
+  for (int i = 0; i < len + 1; i++)
+    a[i]=i;
+}
+
+/* Check we do not split the backedge but keep nice loop form.  */
+/* { dg-final { scan-assembler-times "L\[0-9\]+:" 2 } } */
index fca15e5..60f3c40 100644 (file)
@@ -1171,15 +1171,19 @@ insert_backedge_copies (void)
            {
              tree arg = gimple_phi_arg_def (phi, i);
              edge e = gimple_phi_arg_edge (phi, i);
+             /* We are only interested in copies emitted on critical
+                 backedges.  */
+             if (!(e->flags & EDGE_DFS_BACK)
+                 || !EDGE_CRITICAL_P (e))
+               continue;
 
              /* If the argument is not an SSA_NAME, then we will need a
-                constant initialization.  If the argument is an SSA_NAME with
-                a different underlying variable then a copy statement will be
-                needed.  */
-             if ((e->flags & EDGE_DFS_BACK)
-                 && (TREE_CODE (arg) != SSA_NAME
-                     || SSA_NAME_VAR (arg) != SSA_NAME_VAR (result)
-                     || trivially_conflicts_p (bb, result, arg)))
+                constant initialization.  If the argument is an SSA_NAME then
+                a copy statement may be needed.  First handle the case
+                where we cannot insert before the argument definition.  */
+             if (TREE_CODE (arg) != SSA_NAME
+                 || (gimple_code (SSA_NAME_DEF_STMT (arg)) == GIMPLE_PHI
+                     && trivially_conflicts_p (bb, result, arg)))
                {
                  tree name;
                  gassign *stmt;
@@ -1226,6 +1230,34 @@ insert_backedge_copies (void)
                    gsi_insert_after (&gsi2, stmt, GSI_NEW_STMT);
                  SET_PHI_ARG_DEF (phi, i, name);
                }
+             /* Insert a copy before the definition of the backedge value
+                and adjust all conflicting uses.  */
+             else if (trivially_conflicts_p (bb, result, arg))
+               {
+                 gimple *def = SSA_NAME_DEF_STMT (arg);
+                 if (gimple_nop_p (def)
+                     || gimple_code (def) == GIMPLE_PHI)
+                   continue;
+                 tree name = copy_ssa_name (result);
+                 gimple *stmt = gimple_build_assign (name, result);
+                 imm_use_iterator imm_iter;
+                 gimple *use_stmt;
+                 /* The following matches trivially_conflicts_p.  */
+                 FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, result)
+                   {
+                     if (gimple_bb (use_stmt) != bb
+                         || (gimple_code (use_stmt) != GIMPLE_PHI
+                             && (maybe_renumber_stmts_bb (bb), true)
+                             && gimple_uid (use_stmt) > gimple_uid (def)))
+                       {
+                         use_operand_p use;
+                         FOR_EACH_IMM_USE_ON_STMT (use, imm_iter)
+                           SET_USE (use, name);
+                       }
+                   }
+                 gimple_stmt_iterator gsi = gsi_for_stmt (def);
+                 gsi_insert_before (&gsi, stmt, GSI_SAME_STMT);
+               }
            }
        }