On Thu, Nov 13, 2025 at 6:01 AM Richard Biener <[email protected]> wrote:
>
> We currently remove stmts inside of a FOR_EACH_IMM_USE_STMT iteration
> which can be problematical.  The following adjusts purge_all_uses
> to gather all stmts to remove and remove them in reverse order
> afterwards which also better deals with debug stmt generation.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK?

LGTM but I can't approve it.

>
> Thanks,
> Richard.
>
>         PR ipa/122663
>         * ipa-param-manipulation.cc (purge_all_uses): Collect
>         stmts to remove and process that list in reverse.
> ---
>  gcc/ipa-param-manipulation.cc | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc
> index 11f843c48d1..96ab125dee1 100644
> --- a/gcc/ipa-param-manipulation.cc
> +++ b/gcc/ipa-param-manipulation.cc
> @@ -636,6 +636,7 @@ purge_all_uses (tree name, hash_set <tree> *killed_ssas)
>    imm_use_iterator imm_iter;
>    gimple *stmt;
>    auto_vec <tree, 4> worklist;
> +  auto_vec <gimple *, 4> kill_list;
>
>    worklist.safe_push (name);
>    while (!worklist.is_empty ())
> @@ -664,11 +665,19 @@ purge_all_uses (tree name, hash_set <tree> *killed_ssas)
>           if (!killed_ssas->add (lhs))
>             {
>               worklist.safe_push (lhs);
> -             gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
> -             gsi_remove (&gsi, true);
> +             kill_list.safe_push (stmt);
>             }
>         }
>      }
> +
> +  /* Remove stmts in reverse and afterwards to properly handle debug stmt
> +     generation and to not interfere with immediate use iteration.  */
> +  while (!kill_list.is_empty ())
> +    {
> +      stmt = kill_list.pop ();
> +      gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
> +      gsi_remove (&gsi, true);
> +    }
>  }
>
>  /* Modify actual arguments of a function call in statement currently 
> belonging
> --
> 2.51.0

Reply via email to