dce: add remove_unused_locals conditionally to the todos [PR117096]

This is the updated patch with the suggestion from:
https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665217.html
Where we use a second arg/param to set which passes we want to have
the remove_unused_locals on the dce.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	PR tree-optimization/117096
	* passes.def: Update some of the dce/cd-cde passes setting
	the 2nd arg to true.
	Also remove comment about stdarg since dce does it.
	* tree-ssa-dce.cc (pass_dce): Add remove_unused_locals_p field.
	Update set_pass_param to allow for 2nd param.
	Use remove_unused_locals_p in execute to return TODO_remove_unused_locals.
	(pass_cd_dce): Likewise.
	* tree-stdarg.cc (pass_data_stdarg): Remove TODO_remove_unused_locals.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
This commit is contained in:
Andrew Pinski 2024-10-13 11:16:51 -07:00
parent 0110a381de
commit 60de558581
3 changed files with 19 additions and 12 deletions

View file

@ -92,7 +92,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_early_vrp);
NEXT_PASS (pass_merge_phi);
NEXT_PASS (pass_dse);
NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */);
NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */, true /* remove_unused_locals */);
NEXT_PASS (pass_phiopt, true /* early_p */);
NEXT_PASS (pass_tail_recursion);
NEXT_PASS (pass_if_to_switch);
@ -225,10 +225,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_vrp, false /* final_p*/);
NEXT_PASS (pass_array_bounds);
NEXT_PASS (pass_dse);
NEXT_PASS (pass_dce);
/* pass_stdarg is always run and at this point we execute
TODO_remove_unused_locals to prune CLOBBERs of dead
variables which are otherwise a churn on alias walkings. */
NEXT_PASS (pass_dce, false /* update_address_taken_p */, true /* remove_unused_locals */);
NEXT_PASS (pass_stdarg);
NEXT_PASS (pass_call_cdce);
NEXT_PASS (pass_cselim);
@ -273,7 +270,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_asan);
NEXT_PASS (pass_tsan);
NEXT_PASS (pass_dse, true /* use DR analysis */);
NEXT_PASS (pass_dce);
NEXT_PASS (pass_dce, false /* update_address_taken_p */, false /* remove_unused_locals */);
/* Pass group that runs when 1) enabled, 2) there are loops
in the function. Make sure to run pass_fix_loops before
to discover/remove loops before running the gate function
@ -355,7 +352,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_ccp, true /* nonzero_p */);
NEXT_PASS (pass_warn_restrict);
NEXT_PASS (pass_dse);
NEXT_PASS (pass_dce, true /* update_address_taken_p */);
NEXT_PASS (pass_dce, true /* update_address_taken_p */, true /* remove_unused_locals */);
/* After late DCE we rewrite no longer addressed locals into SSA
form if possible. */
NEXT_PASS (pass_forwprop);

View file

@ -2096,18 +2096,23 @@ public:
opt_pass * clone () final override { return new pass_dce (m_ctxt); }
void set_pass_param (unsigned n, bool param) final override
{
gcc_assert (n == 0);
update_address_taken_p = param;
gcc_assert (n == 0 || n == 1);
if (n == 0)
update_address_taken_p = param;
else if (n == 1)
remove_unused_locals_p = param;
}
bool gate (function *) final override { return flag_tree_dce != 0; }
unsigned int execute (function *) final override
{
return (tree_ssa_dce ()
| (remove_unused_locals_p ? TODO_remove_unused_locals : 0)
| (update_address_taken_p ? TODO_update_address_taken : 0));
}
private:
bool update_address_taken_p;
bool remove_unused_locals_p = false;
}; // class pass_dce
} // anon namespace
@ -2144,18 +2149,23 @@ public:
opt_pass * clone () final override { return new pass_cd_dce (m_ctxt); }
void set_pass_param (unsigned n, bool param) final override
{
gcc_assert (n == 0);
update_address_taken_p = param;
gcc_assert (n == 0 || n == 1);
if (n == 0)
update_address_taken_p = param;
else if (n == 1)
remove_unused_locals_p = param;
}
bool gate (function *) final override { return flag_tree_dce != 0; }
unsigned int execute (function *) final override
{
return (tree_ssa_cd_dce ()
| (remove_unused_locals_p ? TODO_remove_unused_locals : 0)
| (update_address_taken_p ? TODO_update_address_taken : 0));
}
private:
bool update_address_taken_p;
bool remove_unused_locals_p = false;
}; // class pass_cd_dce
} // anon namespace

View file

@ -1114,7 +1114,7 @@ const pass_data pass_data_stdarg =
( PROP_cfg | PROP_ssa ), /* properties_required */
PROP_gimple_lva, /* properties_provided */
0, /* properties_destroyed */
TODO_remove_unused_locals, /* todo_flags_start */
0, /* todo_flags_start */
0, /* todo_flags_finish */
};