diff mbox series

tree-optimization/104960 - unsplit edges after late sinking

Message ID 20220317085052.A032413B6A@imap2.suse-dmz.suse.de
State New
Headers show
Series tree-optimization/104960 - unsplit edges after late sinking | expand

Commit Message

Richard Biener March 17, 2022, 8:50 a.m. UTC
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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

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.
---
 gcc/passes.def                     |  4 ++--
 gcc/testsuite/gcc.dg/gimplefe-37.c |  2 +-
 gcc/tree-ssa-sink.cc               | 13 +++++++++++--
 3 files changed, 14 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/gcc/passes.def b/gcc/passes.def
index c8903b4ec16..3e44797b10f 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 d3ea186d7f9..12f6f64fc2c 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 66d7ae89e90..1c226406feb 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);