The algorithm fwprop uses never reconsiders a possible propagation,
although it could succeed if the def (in the def-use to propagate)
has changed. This causes fwprop to do infinite propagations, like
in the scenario in the PR, where we end up with effectively
B = A
A = B
D = A
where only propagations into the last statement are still tried, and
that loops (it becomes D = B, then back to D = A, etc.)
Fixing this properly isn't easy; this patch instead limits the number
of propagations performed to the number of uses we originally had,
which is the maximum number of propagations that can be done if there
are no such infinite loops.
Bootstrapped and regression checked on powerpc64-linux {-m64,-m32};
is this okay for trunk?
Segher
2017-03-23 Segher Boessenkool <segher@kernel.crashing.org>
PR rtl-optimization/79405
* fwprop.c (propagations_left): New variable.
(forward_propagate_into): Decrement it.
(fwprop_init): Initialize it.
(fw_prop): If the variable has reached zero, stop propagating.
(fwprop_addr): Ditto.
gcc/testsuite/
PR rtl-optimization/79405
gcc.dg/pr79405.c: New testcase.