re PR middle-end/52691 (va_start to builtin_next_arg optimization lost)
authorJakub Jelinek <jakub@redhat.com>
Wed, 28 Mar 2012 14:47:45 +0000 (16:47 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 28 Mar 2012 14:47:45 +0000 (16:47 +0200)
PR middle-end/52691
* tree-ssa-ccp.c (optimize_stdarg_builtin): Optimize
__builtin_va_start to __builtin_next_arg if the latter is
builtin_decl_explicit_p rather than when it is not.

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

From-SVN: r185917

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr52691.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index a33cac30620764a343d5a06db3ba086f35b9ccbb..6a7605ef18a64ceb6e19a55d77f0f86655c18208 100644 (file)
@@ -1,5 +1,10 @@
 2012-03-28  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/52691
+       * tree-ssa-ccp.c (optimize_stdarg_builtin): Optimize
+       __builtin_va_start to __builtin_next_arg if the latter is
+       builtin_decl_explicit_p rather than when it is not.
+
        PR middle-end/52750
        * tree-vect-generic.c (vector_element): Perform multiplication
        for pos in bitsizetype type instead of idx type.
index d3344759cda9f7ed27b1fe72b48664acb980b84f..b965221b1b17baf4af38c4ddafce7fb89a61ea28 100644 (file)
@@ -1,5 +1,8 @@
 2012-03-28  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/52691
+       * gcc.dg/pr52691.c: New test.
+
        PR middle-end/52750
        * gcc.c-torture/compile/pr52750.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr52691.c b/gcc/testsuite/gcc.dg/pr52691.c
new file mode 100644 (file)
index 0000000..7a2d7d8
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR middle-end/52691 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include <stdarg.h>
+
+int
+foo (int a, ...)
+{
+  int b = 0, c = 0;
+  va_list ap;
+  va_start (ap, a);
+  if (a > 1)
+    b = va_arg (ap, double);
+  if (a > 2)
+    c = va_arg (ap, long long);
+  va_end (ap);
+  return a + b + c;
+}
+
+/* { dg-final { scan-tree-dump "__builtin_next_arg" "optimized" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */
+/* { dg-final { scan-tree-dump "__builtin_next_arg" "optimized" { target { powerpc*-*-darwin* powerpc*-*-aix* } } } } */
+/* { dg-final { scan-tree-dump "__builtin_next_arg" "optimized" { target { powerpc*-*-linux* && lp64 } } } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index 2080c06cce649feb62c7a6bcf23e0f696b8c0588..c28006a91320e0807757df627ebeacfff7ea37fa 100644 (file)
@@ -2288,7 +2288,7 @@ optimize_stdarg_builtin (gimple call)
     case BUILT_IN_VA_START:
       if (!va_list_simple_ptr
          || targetm.expand_builtin_va_start != NULL
-          || builtin_decl_explicit_p (BUILT_IN_NEXT_ARG))
+         || !builtin_decl_explicit_p (BUILT_IN_NEXT_ARG))
        return NULL_TREE;
 
       if (gimple_call_num_args (call) != 2)