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.
This commit is contained in:
Richard Biener 2022-03-17 08:10:59 +01:00
parent 7276a18aba
commit 3a7ba8fd0c
3 changed files with 14 additions and 5 deletions

View File

@ -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);

View File

@ -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" } } */

View File

@ -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);