re PR tree-optimization/92930 (GCC incorrectly optimizes away __builtin_apply() calls)
authorJakub Jelinek <jakub@redhat.com>
Sat, 14 Dec 2019 11:18:30 +0000 (12:18 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 14 Dec 2019 11:18:30 +0000 (12:18 +0100)
PR tree-optimization/92930
* ipa-pure-const.c (special_builtin_state): Don't handle
BUILT_IN_APPLY.  Formatting fixes.
(check_call): Formatting fixes.

* gcc.dg/tree-ssa/pr92930.c: New test.

From-SVN: r279394

gcc/ChangeLog
gcc/ipa-pure-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr92930.c [new file with mode: 0644]

index b50155dde0c5414e927d2c41d6acafd32c2d5c17..e0ac204d0e3559d0e9d24a683bc6b6a2d94a615e 100644 (file)
@@ -1,3 +1,10 @@
+2019-12-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/92930
+       * ipa-pure-const.c (special_builtin_state): Don't handle
+       BUILT_IN_APPLY.  Formatting fixes.
+       (check_call): Formatting fixes.
+
 2019-12-14  Iain Sandoe  <iain@sandoe.co.uk>
 
        * config/darwin.h (DARWIN_EXTRA_SPECS): Add new
index a142e0cc8f6b36e3219559aa87f1e17001b5623b..58ab668009a283de146f2b4954fcab5960adcd6f 100644 (file)
@@ -511,35 +511,34 @@ worse_state (enum pure_const_state_e *state, bool *looping,
    but function using them is.  */
 static bool
 special_builtin_state (enum pure_const_state_e *state, bool *looping,
-                       tree callee)
+                      tree callee)
 {
   if (DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
     switch (DECL_FUNCTION_CODE (callee))
       {
-       case BUILT_IN_RETURN:
-       case BUILT_IN_UNREACHABLE:
-       CASE_BUILT_IN_ALLOCA:
-       case BUILT_IN_STACK_SAVE:
-       case BUILT_IN_STACK_RESTORE:
-       case BUILT_IN_EH_POINTER:
-       case BUILT_IN_EH_FILTER:
-       case BUILT_IN_UNWIND_RESUME:
-       case BUILT_IN_CXA_END_CLEANUP:
-       case BUILT_IN_EH_COPY_VALUES:
-       case BUILT_IN_FRAME_ADDRESS:
-       case BUILT_IN_APPLY:
-       case BUILT_IN_APPLY_ARGS:
-       case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT:
-       case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT:
-         *looping = false;
-         *state = IPA_CONST;
-         return true;
-       case BUILT_IN_PREFETCH:
-         *looping = true;
-         *state = IPA_CONST;
-         return true;
-       default:
-         break;
+      case BUILT_IN_RETURN:
+      case BUILT_IN_UNREACHABLE:
+      CASE_BUILT_IN_ALLOCA:
+      case BUILT_IN_STACK_SAVE:
+      case BUILT_IN_STACK_RESTORE:
+      case BUILT_IN_EH_POINTER:
+      case BUILT_IN_EH_FILTER:
+      case BUILT_IN_UNWIND_RESUME:
+      case BUILT_IN_CXA_END_CLEANUP:
+      case BUILT_IN_EH_COPY_VALUES:
+      case BUILT_IN_FRAME_ADDRESS:
+      case BUILT_IN_APPLY_ARGS:
+      case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT:
+      case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT:
+       *looping = false;
+       *state = IPA_CONST;
+       return true;
+      case BUILT_IN_PREFETCH:
+       *looping = true;
+       *state = IPA_CONST;
+       return true;
+      default:
+       break;
       }
   return false;
 }
@@ -624,9 +623,10 @@ check_call (funct_state local, gcall *call, bool ipa)
          case BUILT_IN_LONGJMP:
          case BUILT_IN_NONLOCAL_GOTO:
            if (dump_file)
-             fprintf (dump_file, "    longjmp and nonlocal goto is not const/pure\n");
+             fprintf (dump_file,
+                      "    longjmp and nonlocal goto is not const/pure\n");
            local->pure_const_state = IPA_NEITHER;
-            local->looping = true;
+           local->looping = true;
            break;
          default:
            break;
@@ -1532,7 +1532,7 @@ propagate_pure_const (void)
                    }
                }
              else if (special_builtin_state (&edge_state, &edge_looping,
-                                              y->decl))
+                                             y->decl))
                ;
              else
                state_from_flags (&edge_state, &edge_looping,
index e182244b2081c3f9da5ed7386e2d9a87fb2310f7..da0d3abe350f2871338ca90d0a75130a771c3d04 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/92930
+       * gcc.dg/tree-ssa/pr92930.c: New test.
+
 2019-12-13  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/91582
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr92930.c b/gcc/testsuite/gcc.dg/tree-ssa/pr92930.c
new file mode 100644 (file)
index 0000000..67e604b
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR tree-optimization/92930 */
+/* { dg-do compile { target untyped_assembly } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump "__builtin_apply " "optimized" } } */
+/* { dg-final { scan-tree-dump "__builtin_apply_args" "optimized" } } */
+
+void foo (int a, int b, int c, int d, int e, int f, int g);
+
+static void bar (int a, ...)
+{
+  __builtin_apply (foo, __builtin_apply_args (), 20);
+}
+
+int
+main ()
+{
+  bar (1024, 1025, 1026, 1027, 1028, 1029, 1030);
+  return 0;
+}