On 12/11/25 1:38 AM, Jakub Jelinek wrote:
Hi!

REG_UNUSED and REG_DEAD notes are only valid when computed by df
with df_note_add_problem () before df_analyze ().
Generally, especially CSE/GCSE optimizations can invalidate those
notes by reusing the REG_UNUSED results later on, unfortunately dropping
REG_UNUSED notes in such cases is not very easy.
See e.g. PR113059 and PR40209 for additional details.

Most users of REG_UNUSED/REG_DEAD notes add the note problems, but
single_set function is called from many of the passes and requiring
that df_note_add_problem () is done in each such a case would be very
slow and would need some checking.

The following patch instead limits the use of REG_UNUSED notes to
passes which have the note problem computed (i.e. df && df_note), and
for pseudos as a fallback uses DF_REG_USE_COUNT == 0 check if at least
df is computed.

Bootstrapped/regtested on x86_64-linux, i686-linux and aarch64-linux,
ok for trunk?

2025-12-11  Jakub Jelinek  <[email protected]>

        PR rtl-optimization/121852
        * rtlanal.cc (single_set_2): Only look for REG_UNUSED notes if
        df && df_note, otherwise if df and SET_DEST is a pseudo with
        DF_REG_USE_COUNT 0, assume it is unused as well.  Otherwise
        assume it may be used.

        * gcc.dg/pr121852.c: New test.
OK.

Jeff

Reply via email to