aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-03-17 08:10:59 +0100
committerRichard Biener <rguenther@suse.de>2022-03-17 09:51:09 +0100
commit3a7ba8fd0cda387809e4902328af2473662b6a4a (patch)
tree32cb62d227c852f67eb5f529f398045fe83aeff9
parent7276a18aba41eed65c0cf535ae029e0ceeca6c77 (diff)
downloadgcc-3a7ba8fd0cda387809e4902328af2473662b6a4a.zip
gcc-3a7ba8fd0cda387809e4902328af2473662b6a4a.tar.gz
gcc-3a7ba8fd0cda387809e4902328af2473662b6a4a.tar.bz2
tree-optimization/104960 - unsplit edges after late sinking
Something went wrong when testing the earlier patch to move the late sinking to before the late phiopt for PR102008. The following makes sure to unsplit edges after the late sinking since the split edges confuse the following phiopt leading to missed optimizations. I've went for a new pass parameter for this to avoid changing the CFG after the early sinking pass at this point. 2022-03-17 Richard Biener <rguenther@suse.de> PR tree-optimization/104960 * passes.def: Add pass parameter to pass_sink_code, mark last one to unsplit edges. * tree-ssa-sink.cc (pass_sink_code::set_pass_param): New. (pass_sink_code::execute): Always execute TODO_cleanup_cfg when we need to unsplit edges. * gcc.dg/gimplefe-37.c: Adjust to allow either the true or false edge to have a forwarder.
-rw-r--r--gcc/passes.def4
-rw-r--r--gcc/testsuite/gcc.dg/gimplefe-37.c2
-rw-r--r--gcc/tree-ssa-sink.cc13
3 files changed, 14 insertions, 5 deletions
diff --git a/gcc/passes.def b/gcc/passes.def
index c8903b4..3e44797 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -259,7 +259,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_lim);
NEXT_PASS (pass_walloca, false);
NEXT_PASS (pass_pre);
- NEXT_PASS (pass_sink_code);
+ NEXT_PASS (pass_sink_code, false /* unsplit edges */);
NEXT_PASS (pass_sancov);
NEXT_PASS (pass_asan);
NEXT_PASS (pass_tsan);
@@ -349,7 +349,7 @@ along with GCC; see the file COPYING3. If not see
/* After late CD DCE we rewrite no longer addressed locals into SSA
form if possible. */
NEXT_PASS (pass_forwprop);
- NEXT_PASS (pass_sink_code);
+ NEXT_PASS (pass_sink_code, true /* unsplit edges */);
NEXT_PASS (pass_phiopt, false /* early_p */);
NEXT_PASS (pass_fold_builtins);
NEXT_PASS (pass_optimize_widening_mul);
diff --git a/gcc/testsuite/gcc.dg/gimplefe-37.c b/gcc/testsuite/gcc.dg/gimplefe-37.c
index d3ea186..12f6f64 100644
--- a/gcc/testsuite/gcc.dg/gimplefe-37.c
+++ b/gcc/testsuite/gcc.dg/gimplefe-37.c
@@ -22,6 +22,6 @@ main (int argc)
/* { dg-final { scan-tree-dump-times "<bb \[0-9\]> \\\[count: 3" 2 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "<bb \[0-9\]> \\\[count: 2" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "<bb \[0-9\]> \\\[count: \[12\]" 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times "goto <bb \[0-9\]>; \\\[33\\\.33%\\\]" 1 "optimized" } } */
/* { dg-final { scan-tree-dump-times "goto <bb \[0-9\]>; \\\[66\\\.67%\\\]" 1 "optimized" } } */
diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc
index 66d7ae8..1c22640 100644
--- a/gcc/tree-ssa-sink.cc
+++ b/gcc/tree-ssa-sink.cc
@@ -822,14 +822,21 @@ class pass_sink_code : public gimple_opt_pass
{
public:
pass_sink_code (gcc::context *ctxt)
- : gimple_opt_pass (pass_data_sink_code, ctxt)
+ : gimple_opt_pass (pass_data_sink_code, ctxt), unsplit_edges (false)
{}
/* opt_pass methods: */
virtual bool gate (function *) { return flag_tree_sink != 0; }
virtual unsigned int execute (function *);
opt_pass *clone (void) { return new pass_sink_code (m_ctxt); }
+ void set_pass_param (unsigned n, bool param)
+ {
+ gcc_assert (n == 0);
+ unsplit_edges = param;
+ }
+private:
+ bool unsplit_edges;
}; // class pass_sink_code
unsigned int
@@ -837,11 +844,13 @@ pass_sink_code::execute (function *fun)
{
loop_optimizer_init (LOOPS_NORMAL);
split_edges_for_insertion ();
+ /* Arrange for the critical edge splitting to be undone if requested. */
+ unsigned todo = unsplit_edges ? TODO_cleanup_cfg : 0;
connect_infinite_loops_to_exit ();
memset (&sink_stats, 0, sizeof (sink_stats));
calculate_dominance_info (CDI_DOMINATORS);
calculate_dominance_info (CDI_POST_DOMINATORS);
- unsigned todo = sink_code_in_bb (EXIT_BLOCK_PTR_FOR_FN (fun));
+ todo |= sink_code_in_bb (EXIT_BLOCK_PTR_FOR_FN (fun));
statistics_counter_event (fun, "Sunk statements", sink_stats.sunk);
statistics_counter_event (fun, "Commoned stores", sink_stats.commoned);
free_dominance_info (CDI_POST_DOMINATORS);