On Wed, Jan 31, 2024 at 9:23 AM Jakub Jelinek <ja...@redhat.com> wrote:
>
> Hi!
>
> The move of the vzeroupper pass from after reload pass to after
> postreload_cse helped only partially, CSE-like passes can still invalidate
> those notes (especially REG_UNUSED) if they use some earlier register
> holding some value later on in the IL.
>
> So, either we could try to move it one pass further after gcse2 and hope
> no later pass invalidates the notes, or the following patch attempts to
> restore the REG_DEAD/REG_UNUSED state from GCC 13 and earlier, where
> the LRA or reload passes remove all REG_DEAD/REG_UNUSED notes and the notes
> reappear only at the start of dse2 pass when it calls
>   df_note_add_problem ();
>   df_analyze ();
> So, effectively
>           NEXT_PASS (pass_postreload_cse);
>           NEXT_PASS (pass_gcse2);
>           NEXT_PASS (pass_split_after_reload);
>           NEXT_PASS (pass_ree);
>           NEXT_PASS (pass_compare_elim_after_reload);
>           NEXT_PASS (pass_thread_prologue_and_epilogue);
> passes operate without those notes in the IL.
> While in GCC 14 mode switching computes the notes problem at the start of
> vzeroupper, the patch below removes them at the end of the pass again, so
> that the above passes continue to operate without them.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2024-01-31  Jakub Jelinek  <ja...@redhat.com>
>
>         PR target/113059
>         * config/i386/i386-features.cc (rest_of_handle_insert_vzeroupper):
>         Remove REG_DEAD/REG_UNUSED notes at the end of the pass before
>         df_analyze call.

Not really a review, but let's rubber stamp this workaround OK.

Thanks,
Uros.

>
> --- gcc/config/i386/i386-features.cc.jj 2024-01-08 12:15:13.611477047 +0100
> +++ gcc/config/i386/i386-features.cc    2024-01-30 12:36:27.834515803 +0100
> @@ -2664,6 +2664,32 @@ rest_of_handle_insert_vzeroupper (void)
>    /* Call optimize_mode_switching.  */
>    g->get_passes ()->execute_pass_mode_switching ();
>
> +  /* LRA removes all REG_DEAD/REG_UNUSED notes and normally they
> +     reappear in the IL only at the start of pass_rtl_dse2, which does
> +     df_note_add_problem (); df_analyze ();
> +     The vzeroupper is scheduled after postreload_cse pass and mode
> +     switching computes the notes as well, the problem is that e.g.
> +     pass_gcse2 doesn't maintain the notes, see PR113059 and
> +     PR112760.  Remove the notes now to restore status quo ante
> +     until we figure out how to maintain the notes or what else
> +     to do.  */
> +  basic_block bb;
> +  rtx_insn *insn;
> +  FOR_EACH_BB_FN (bb, cfun)
> +    FOR_BB_INSNS (bb, insn)
> +      if (NONDEBUG_INSN_P (insn))
> +       {
> +         rtx *pnote = &REG_NOTES (insn);
> +         while (*pnote != 0)
> +           {
> +             if (REG_NOTE_KIND (*pnote) == REG_DEAD
> +                 || REG_NOTE_KIND (*pnote) == REG_UNUSED)
> +               *pnote = XEXP (*pnote, 1);
> +             else
> +               pnote = &XEXP (*pnote, 1);
> +           }
> +       }
> +
>    df_analyze ();
>    return 0;
>  }
>
>         Jakub
>

Reply via email to