]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR target/64979 (stdarg optimization not able to find escape sites in...
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Feb 2015 12:17:41 +0000 (13:17 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 12 Feb 2015 12:17:41 +0000 (13:17 +0100)
Backported from mainline
2015-02-09  Jakub Jelinek  <jakub@redhat.com>

PR target/64979
* tree-stdarg.c (pass_stdarg::execute): Scan phi node args for
va_list escapes.

* gcc.dg/tree-ssa/stdarg-7.c: New test.
* gcc.c-torture/execute/pr64979.c: New test.

From-SVN: r220645

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr64979.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/stdarg-7.c [new file with mode: 0644]
gcc/tree-stdarg.c

index 42ca6f12ebb63ac3c59132f5a8de4ae350c05893..469ee31c9082a033a9a1510c1ba85d0dc432ab7e 100644 (file)
@@ -1,3 +1,12 @@
+2015-02-12  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2015-02-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/64979
+       * tree-stdarg.c (pass_stdarg::execute): Scan phi node args for
+       va_list escapes.
+
 2015-02-11  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/alpha/alpha.md (reload_out<mode>_aligned): Make operands 2
index f20e49897b5a89d47d5d59b118e77ac13ad26426..5ecad07979b6bc876a98670b98dff6c7d2c22ed0 100644 (file)
@@ -1,3 +1,12 @@
+2015-02-12  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2015-02-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/64979
+       * gcc.dg/tree-ssa/stdarg-7.c: New test.
+       * gcc.c-torture/execute/pr64979.c: New test.
+
 2015-02-11  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr64979.c b/gcc/testsuite/gcc.c-torture/execute/pr64979.c
new file mode 100644 (file)
index 0000000..ccb4608
--- /dev/null
@@ -0,0 +1,36 @@
+/* PR target/64979 */
+
+#include <stdarg.h>
+
+void __attribute__((noinline, noclone))
+bar (int x, va_list *ap)
+{
+  if (ap)
+    {
+      int i;
+      for (i = 0; i < 10; i++)
+       if (i != va_arg (*ap, int))
+         __builtin_abort ();
+      if (va_arg (*ap, double) != 0.5)
+       __builtin_abort ();
+    }
+}
+
+void __attribute__((noinline, noclone))
+foo (int x, ...)
+{
+  va_list ap;
+  int n;
+
+  va_start (ap, x);
+  n = va_arg (ap, int);
+  bar (x, (va_list *) ((n == 0) ? ((void *) 0) : &ap));
+  va_end (ap);
+}
+
+int
+main ()
+{
+  foo (100, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0.5);
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-7.c b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-7.c
new file mode 100644 (file)
index 0000000..9b497c0
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR target/64979 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-stdarg" } */
+
+#include <stdarg.h>
+
+void bar (int x, va_list *ap);
+
+void
+foo (int x, ...)
+{
+  va_list ap;
+  int n;
+
+  va_start (ap, x);
+  n = va_arg (ap, int);
+  bar (x, (va_list *) ((n == 0) ? ((void *) 0) : &ap));
+  va_end (ap);
+}
+
+/* { dg-final { scan-tree-dump "foo: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" } } */
+/* { dg-final { cleanup-tree-dump "stdarg" } } */
index 8ad9fc2d22e48917f843b21eded1b527f783e70c..d6f81a104eda4c8944b069106ef8c09310bc8567 100644 (file)
@@ -809,21 +809,22 @@ execute_optimize_stdarg (void)
       /* For va_list_simple_ptr, we have to check PHI nodes too.  We treat
         them as assignments for the purpose of escape analysis.  This is
         not needed for non-simple va_list because virtual phis don't perform
-        any real data movement.  */
-      if (va_list_simple_ptr)
-       {
-         tree lhs, rhs;
-         use_operand_p uop;
-         ssa_op_iter soi;
+        any real data movement.  Also, check PHI nodes for taking address of
+        the va_list vars.  */
+      tree lhs, rhs;
+      use_operand_p uop;
+      ssa_op_iter soi;
 
-         for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
-           {
-             gimple phi = gsi_stmt (i);
-             lhs = PHI_RESULT (phi);
+      for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
+       {
+         gimple phi = gsi_stmt (i);
+         lhs = PHI_RESULT (phi);
 
-             if (virtual_operand_p (lhs))
-               continue;
+         if (virtual_operand_p (lhs))
+           continue;
 
+         if (va_list_simple_ptr)
+           {
              FOR_EACH_PHI_ARG (uop, phi, soi, SSA_OP_USE)
                {
                  rhs = USE_FROM_PTR (uop);
@@ -846,6 +847,22 @@ execute_optimize_stdarg (void)
                    }
                }
            }
+
+         for (unsigned j = 0; !va_list_escapes
+                              && j < gimple_phi_num_args (phi); ++j)
+           if ((!va_list_simple_ptr
+                || TREE_CODE (gimple_phi_arg_def (phi, j)) != SSA_NAME)
+               && walk_tree (gimple_phi_arg_def_ptr (phi, j),
+                             find_va_list_reference, &wi, NULL))
+             {
+               if (dump_file && (dump_flags & TDF_DETAILS))
+                 {
+                   fputs ("va_list escapes in ", dump_file);
+                   print_gimple_stmt (dump_file, phi, 0, dump_flags);
+                   fputc ('\n', dump_file);
+                 }
+               va_list_escapes = true;
+             }
        }
 
       for (i = gsi_start_bb (bb);
@@ -868,8 +885,8 @@ execute_optimize_stdarg (void)
 
          if (is_gimple_assign (stmt))
            {
-             tree lhs = gimple_assign_lhs (stmt);
-             tree rhs = gimple_assign_rhs1 (stmt);
+             lhs = gimple_assign_lhs (stmt);
+             rhs = gimple_assign_rhs1 (stmt);
 
              if (va_list_simple_ptr)
                {