gnu/gcc/f8dce99ad72e98b72df2b1a0fc126409fa7d3c1c backprop: Create new SSA names
backprop currently takes the shortcut of reusing SSA names when changing
their value. The original justification for this was that backprop only
makes changes that are acceptable to all (non-debug) users. It seemed
pointless to go to the trouble of creating a new SSA name, substituting
into all users, creating new SSA names for dependent statements that also
change value, and so on. Debug instructions could be dealt with using
insert_debug_temp_for_var_def, which would be needed in any case.
(This patch still uses insert_debug_temp_for_var_def.)
See:
https://gcc.gnu.org/pipermail/gcc-patches/2015-October/431463.html
https://gcc.gnu.org/pipermail/gcc-patches/2015-October/431468.html
for the original discussion.
However, Robin's upcoming changes to support backpropagating nonzero
bits information runs into the problem that we also need to update
or invalidate range information. That update would spread to the
same places that an SSA rename would. Rather than fight the system
regarding cached information, it seemed better to go with the system
by creating new SSA names.
This is more complicated compared to the status quo, but maybe not
much more so than the status quo plus a flow-sensitive info update.
The change also allows an SSA name to be replaced by any gimple
value. That isn't often useful for the current pass, although
gcc.dg/tree-ssa/backprop-1.c gives an artificial example involving
phi nodes and gcc.dg/torture/pr116922.c gives an example in which
a division gets folded to 1. However, allowing general replacements
should be useful for Robin's work, which otherwise has to create new
assignments and leave other passes to propagate them away.
Hopefully the comments in the patch explain the approach.
gcc/
* gimple-ssa-backprop.cc: Update the comment at head of the file.
(var_info::new_value, var_info::seq): New member variables.
(var_info::var_info): Initialize them.
(remove_unused_var): Replace with...
(remove_dead_stmt): ...this new function.
(note_replacement): Delete.
(backprop::prepare_change): Likewise.
(backprop::complete_change): Likewise.
(backprop::set_new_value): New function.
(backprop::subst_operand): Likewise.
(backprop::finish_stmt): Likewise.
(backprop::optimize_builtin_call): Replace the lhs and info parameters
with a var_info parameter. Create a new statement rather than
changing the existing one.
(backprop::optimize_assign): Likewise.
(backprop::optimize_phi): Likewise.
(backprop::replace_assign_rhs): Likewise, but replace gassign and lhs
parameters.
(backprop::propagate_change): New function.
(backprop::commit_replacement): Likewise.
(backprop::execute): Update phase 3 for the above changes. Do not
alter the original statements during phase 3. If one SSA name
is scheduled to be replaced, also require all its users in m_vars
to be replaced. Add a new phase that performs the scheduled
replacements.
gcc/testsuite/
* gcc.dg/tree-ssa/backprop-7.c: New test.
2 files changed