]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Control all jump threading passes with -fjump-threads.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 27 Sep 2021 14:41:01 +0000 (16:41 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Tue, 28 Sep 2021 06:17:29 +0000 (08:17 +0200)
Last year I mentioned that -fthread-jumps was being ignored by the
majority of our jump threading passes, and Jeff said he'd be in favor
of fixing this.

This patch remedies the situation, but it does change existing behavior.
Currently -fthread-jumps is only enabled for -O2, -O3, and -Os.  This
means that even if we restricted all jump threading passes with
-fthread-jumps, DOM jump threading would still seep through since it
runs at -O1.

I propose this patch, but it does mean that DOM jump threading would
have to be explicitly enabled with -O1 -fthread-jumps.

gcc/ChangeLog:

* tree-ssa-threadbackward.c (pass_thread_jumps::gate): Check
flag_thread_jumps.
(pass_early_thread_jumps::gate): Same.
* tree-ssa-threadedge.c (jump_threader::thread_outgoing_edges):
Return if !flag_thread_jumps.
* tree-ssa-threadupdate.c
(jt_path_registry::register_jump_thread): Assert that
flag_thread_jumps is true.

gcc/testsuite/ChangeLog:

* gcc.dg/auto-init-uninit-1.c: Add -fthread-jumps.
* gcc.dg/auto-init-uninit-15.c: Same.
* gcc.dg/guality/example.c: Same.
* gcc.dg/loop-8.c: Same.
* gcc.dg/strlenopt-40.c: Same.
* gcc.dg/tree-ssa/pr18133-2.c: Same.
* gcc.dg/tree-ssa/pr18134.c: Same.
* gcc.dg/uninit-1.c: Same.
* gcc.dg/uninit-pr44547.c: Same.
* gcc.dg/uninit-pr59970.c: Same.

13 files changed:
gcc/testsuite/gcc.dg/auto-init-uninit-1.c
gcc/testsuite/gcc.dg/auto-init-uninit-15.c
gcc/testsuite/gcc.dg/guality/example.c
gcc/testsuite/gcc.dg/loop-8.c
gcc/testsuite/gcc.dg/strlenopt-40.c
gcc/testsuite/gcc.dg/tree-ssa/pr18133-2.c
gcc/testsuite/gcc.dg/tree-ssa/pr18134.c
gcc/testsuite/gcc.dg/uninit-1.c
gcc/testsuite/gcc.dg/uninit-pr44547.c
gcc/testsuite/gcc.dg/uninit-pr59970.c
gcc/tree-ssa-threadbackward.c
gcc/tree-ssa-threadedge.c
gcc/tree-ssa-threadupdate.c

index 502db591222a8256acc97a41e5c5ce153f313dda..ce8909623ab386ef862de217ab660c88cbb39a20 100644 (file)
@@ -1,5 +1,5 @@
 /* Spurious uninitialized variable warnings, case 1.
    Taken from cppfiles.c (merge_include_chains) */
 /* { dg-do compile } */
-/* { dg-options "-O -Wuninitialized -ftrivial-auto-var-init=zero" } */
+/* { dg-options "-O -Wuninitialized -fthread-jumps -ftrivial-auto-var-init=zero" } */
 #include "uninit-1.c"
index 121f0cff274a3732ff6b233a5a0391111fcc6a77..b8f6e2b57d59b67be55188b1332c78b4fe6ccd1d 100644 (file)
@@ -5,7 +5,7 @@
    But it is of course ok if we warn in bar about uninitialized use
    of j.  (not xfailed alternative)  */
 /* { dg-do compile } */
-/* { dg-options "-O1 -Wuninitialized -ftrivial-auto-var-init=zero" } */
+/* { dg-options "-O1 -Wuninitialized -fthread-jumps -ftrivial-auto-var-init=zero" } */
 
 inline int
 foo (int i)
index 6f1c017a25325de4fc5e68bead7796136139831f..37564e55cd1997d8a5ac54f78cce5478d63e26dd 100644 (file)
@@ -1,4 +1,3 @@
-/* { dg-do run { xfail { ! aarch64*-*-* } } } */
 /* { dg-options "-g" } */
 /* { dg-xfail-run-if "" aarch64*-*-* "*" { "-O[01g]" } } */
 
index 90ea1c4552438c53c672582791e16501960c79eb..e5218eb4053b188964b3f24a0d5af0276b7e4292 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -fdump-rtl-loop2_invariant" } */
+/* { dg-options "-O1 -fthread-jumps -fdump-rtl-loop2_invariant" } */
 /* { dg-skip-if "unexpected IV" { "hppa*-*-* mips*-*-* visium-*-* powerpc*-*-* riscv*-*-* mmix-*-* vax-*-*" } } */
 /* Load immediate on condition is available from z13 on and prevents moving
    the load out of the loop, so always run this test with -march=zEC12 that
index 7a97ebb8fe5be4b9e9ebd2d81238e9b63a4fd6e2..7b7991047081df3aeda23536a3a0b0da2c7def45 100644 (file)
@@ -1,7 +1,7 @@
 /* PR tree-optimization/83671 - fix for false positive reported by
    -Wstringop-overflow does not work with inlining
    { dg-do compile }
-   { dg-options "-O1 -fdump-tree-optimized" } */
+   { dg-options "-O1 -fthread-jumps -fdump-tree-optimized" } */
 
 #include "strlenopt.h"
 
index 8717640e3272267604cd741efe8c35b590952a05..1b409852189f6e409c14976aae53811a32f4ee9c 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized-blocks" } */
+/* { dg-options "-O1 -fthread-jumps -fdump-tree-optimized-blocks" } */
 
 int c, d;
 
index cd40ab2c162bd168b120d200f694e97bea89dbd4..d7f5d241eb9b0755289f14b620a8cf5b50ec4e45 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -fthread-jumps -fdump-tree-optimized" } */
 
 int  foo (int a)
 {
index 060ec250ba7494ee7e90bab3724c3be3182edf7b..156d34ff732e1aacc0651f5aa8ede825e42b6555 100644 (file)
@@ -1,7 +1,7 @@
 /* Spurious uninitialized variable warnings, case 1.
    Taken from cppfiles.c (merge_include_chains) */
 /* { dg-do compile } */
-/* { dg-options "-O -Wuninitialized" } */
+/* { dg-options "-O -Wuninitialized -fthread-jumps" } */
 
 struct list
 {
index ee1035ad7b8094ab2535bf2861f16c4eaae47593..f1c3b034d14d8aa0caf843512c9f3626e98e848a 100644 (file)
@@ -1,7 +1,7 @@
 /* PR tree-optimization/44547 - -Wuninitialized reports false warning
    in nested switch statements
    { dg-do compile }
-   { dg-options "-O1 -Wall" } */
+   { dg-options "-O1 -Wall -fthread-jumps" } */
 
 __attribute__ ((noipa)) int test_O1 (int argc)
 {
index 145af657a76c2dfaa16453cc8a45c7c5f713eb74..d0c41b8480dbc2c3724d89d9ed41d6a7cf9151c9 100644 (file)
@@ -41,7 +41,7 @@ d_demangle_callback_O1 (const char *mangled)
 #pragma GCC pop_options
 
 
-#pragma GCC optimize ("Og")
+#pragma GCC optimize ("Og,thread-jumps")
 
 __attribute__ ((noipa)) int
 d_demangle_callback_Og (const char *mangled)
index e6819fe148ca53dffa813c97d4eefef5dc197986..28c7ef8c872b14be6b3ac32ab055f163a10bdc41 100644 (file)
@@ -943,7 +943,7 @@ public:
 bool
 pass_thread_jumps::gate (function *fun ATTRIBUTE_UNUSED)
 {
-  return flag_expensive_optimizations;
+  return flag_thread_jumps && flag_expensive_optimizations;
 }
 
 // Try to thread blocks in FUN.  Return TRUE if any jump thread paths were
@@ -1013,7 +1013,7 @@ public:
 bool
 pass_early_thread_jumps::gate (function *fun ATTRIBUTE_UNUSED)
 {
-  return true;
+  return flag_thread_jumps;
 }
 
 unsigned int
index 0b59cb4845c303b8907407fd4c5f4328ca3c141b..a63a9764ff87040f97e4eb0c6bca58d6232b3c9d 100644 (file)
@@ -1196,6 +1196,9 @@ jump_threader::thread_outgoing_edges (basic_block bb)
   int flags = (EDGE_IGNORE | EDGE_COMPLEX | EDGE_ABNORMAL);
   gimple *last;
 
+  if (!flag_thread_jumps)
+    return;
+
   /* If we have an outgoing edge to a block with multiple incoming and
      outgoing edges, then we may be able to thread the edge, i.e., we
      may be able to statically determine which of the outgoing edges
index 2b9b8f8127489e06c24d8349fd4aa042baa2e278..cf96c9036683c619628568d179e12ce7690ec7ed 100644 (file)
@@ -2822,6 +2822,8 @@ jt_path_registry::cancel_invalid_paths (vec<jump_thread_edge *> &path)
 bool
 jt_path_registry::register_jump_thread (vec<jump_thread_edge *> *path)
 {
+  gcc_checking_assert (flag_thread_jumps);
+
   if (!dbg_cnt (registered_jump_thread))
     {
       path->release ();