From e475ae9bbf0c85a7d60f236c5a744e163a9ef7b8 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Mon, 27 Sep 2021 16:41:01 +0200 Subject: [PATCH] Control all jump threading passes with -fjump-threads. 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. --- gcc/testsuite/gcc.dg/auto-init-uninit-1.c | 2 +- gcc/testsuite/gcc.dg/auto-init-uninit-15.c | 2 +- gcc/testsuite/gcc.dg/guality/example.c | 1 - gcc/testsuite/gcc.dg/loop-8.c | 2 +- gcc/testsuite/gcc.dg/strlenopt-40.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/pr18133-2.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/pr18134.c | 2 +- gcc/testsuite/gcc.dg/uninit-1.c | 2 +- gcc/testsuite/gcc.dg/uninit-pr44547.c | 2 +- gcc/testsuite/gcc.dg/uninit-pr59970.c | 2 +- gcc/tree-ssa-threadbackward.c | 4 ++-- gcc/tree-ssa-threadedge.c | 3 +++ gcc/tree-ssa-threadupdate.c | 2 ++ 13 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gcc/testsuite/gcc.dg/auto-init-uninit-1.c b/gcc/testsuite/gcc.dg/auto-init-uninit-1.c index 502db591222a..ce8909623ab3 100644 --- a/gcc/testsuite/gcc.dg/auto-init-uninit-1.c +++ b/gcc/testsuite/gcc.dg/auto-init-uninit-1.c @@ -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" diff --git a/gcc/testsuite/gcc.dg/auto-init-uninit-15.c b/gcc/testsuite/gcc.dg/auto-init-uninit-15.c index 121f0cff274a..b8f6e2b57d59 100644 --- a/gcc/testsuite/gcc.dg/auto-init-uninit-15.c +++ b/gcc/testsuite/gcc.dg/auto-init-uninit-15.c @@ -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) diff --git a/gcc/testsuite/gcc.dg/guality/example.c b/gcc/testsuite/gcc.dg/guality/example.c index 6f1c017a2532..37564e55cd19 100644 --- a/gcc/testsuite/gcc.dg/guality/example.c +++ b/gcc/testsuite/gcc.dg/guality/example.c @@ -1,4 +1,3 @@ -/* { dg-do run { xfail { ! aarch64*-*-* } } } */ /* { dg-options "-g" } */ /* { dg-xfail-run-if "" aarch64*-*-* "*" { "-O[01g]" } } */ diff --git a/gcc/testsuite/gcc.dg/loop-8.c b/gcc/testsuite/gcc.dg/loop-8.c index 90ea1c455243..e5218eb4053b 100644 --- a/gcc/testsuite/gcc.dg/loop-8.c +++ b/gcc/testsuite/gcc.dg/loop-8.c @@ -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 diff --git a/gcc/testsuite/gcc.dg/strlenopt-40.c b/gcc/testsuite/gcc.dg/strlenopt-40.c index 7a97ebb8fe5b..7b7991047081 100644 --- a/gcc/testsuite/gcc.dg/strlenopt-40.c +++ b/gcc/testsuite/gcc.dg/strlenopt-40.c @@ -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" diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr18133-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr18133-2.c index 8717640e3272..1b409852189f 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr18133-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr18133-2.c @@ -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; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c b/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c index cd40ab2c162b..d7f5d241eb9b 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr18134.c @@ -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) { diff --git a/gcc/testsuite/gcc.dg/uninit-1.c b/gcc/testsuite/gcc.dg/uninit-1.c index 060ec250ba74..156d34ff732e 100644 --- a/gcc/testsuite/gcc.dg/uninit-1.c +++ b/gcc/testsuite/gcc.dg/uninit-1.c @@ -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 { diff --git a/gcc/testsuite/gcc.dg/uninit-pr44547.c b/gcc/testsuite/gcc.dg/uninit-pr44547.c index ee1035ad7b80..f1c3b034d14d 100644 --- a/gcc/testsuite/gcc.dg/uninit-pr44547.c +++ b/gcc/testsuite/gcc.dg/uninit-pr44547.c @@ -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) { diff --git a/gcc/testsuite/gcc.dg/uninit-pr59970.c b/gcc/testsuite/gcc.dg/uninit-pr59970.c index 145af657a76c..d0c41b8480db 100644 --- a/gcc/testsuite/gcc.dg/uninit-pr59970.c +++ b/gcc/testsuite/gcc.dg/uninit-pr59970.c @@ -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) diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c index e6819fe148ca..28c7ef8c872b 100644 --- a/gcc/tree-ssa-threadbackward.c +++ b/gcc/tree-ssa-threadbackward.c @@ -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 diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index 0b59cb4845c3..a63a9764ff87 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -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 diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index 2b9b8f812748..cf96c9036683 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -2822,6 +2822,8 @@ jt_path_registry::cancel_invalid_paths (vec &path) bool jt_path_registry::register_jump_thread (vec *path) { + gcc_checking_assert (flag_thread_jumps); + if (!dbg_cnt (registered_jump_thread)) { path->release (); -- 2.47.2