> Am 09.03.2024 um 09:36 schrieb Jakub Jelinek <ja...@redhat.com>:
>
> Hi!
>
> Before the recent PR111267 r14-8319 fwprop changes, fwprop would never try
> to propagate what was not considered PROFITABLE, where the profitable part
> actually was partly about profitability, partly about very good reasons
> not to actually propagate and partly for cases where propagation is
> completely incorrect.
> In particular, classify_result has:
> /* Allow (subreg (mem)) -> (mem) simplifications with the following
> exceptions:
> 1) Propagating (mem)s into multiple uses is not profitable.
> 2) Propagating (mem)s across EBBs may not be profitable if the source EBB
> runs less frequently.
> 3) Propagating (mem)s into paradoxical (subreg)s is not profitable.
> 4) Creating new (mem/v)s is not correct, since DCE will not remove the old
> ones. */
> if (single_use_p
> && single_ebb_p
> && SUBREG_P (old_rtx)
> && !paradoxical_subreg_p (old_rtx)
> && MEM_P (new_rtx)
> && !MEM_VOLATILE_P (new_rtx))
> return PROFITABLE;
> and didn't mark any other MEM_P (new_rtx) or rtxes which contain
> a MEM in its subrtxes as PROFITABLE. Now, since r14-8319 profitable_p
> method has been renamed to likely_profitable_p and has just a minor role.
> Now, rule 4) above is something that isn't about profitability, but about
> correct behavior, if you propagate mem/v, the code is miscompiled.
> This particular case has been fixed elsewhere by Haochen in r14-9379.
> But I think even the 1) and 2) and maybe 3) are a strong don't do it,
> don't rely solely on rtx costs, increasing the number of loads of the same
> memory, even when cached, is undesirable, canceling load hoisting can
> be undesirable as well.
>
> So, the following patch restores previous behavior of src contains any MEMs,
> in that case likely_profitable_p () is taken as the old profitable_p ()
> as a requirement rather than just a hint. For propagation of something
> which doesn't load from memory this keeps the r14-8319 behavior.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok
Richard
> 2024-03-09 Jakub Jelinek <ja...@redhat.com>
>
> PR target/114284
> * fwprop.cc (try_fwprop_subst_pattern): Don't propagate
> src containing MEMs unless prop.likely_profitable_p ().
>
> --- gcc/fwprop.cc.jj 2024-03-08 09:07:29.371626376 +0100
> +++ gcc/fwprop.cc 2024-03-08 16:18:16.125853619 +0100
> @@ -451,6 +451,7 @@ try_fwprop_subst_pattern (obstack_waterm
>
> if (!prop.likely_profitable_p ()
> && (prop.changed_mem_p ()
> + || contains_mem_rtx_p (src)
> || use_insn->is_asm ()
> || !single_set (use_rtl)))
> {
>
> Jakub
>