On Thu, Sep 5, 2024 at 8:25 AM Andrew Pinski <[email protected]> wrote:
>
> When optimize_memcpy was added in r7-5443-g7b45d0dfeb5f85,
> a path was added such that a statement was turned into a non-throwing
> statement and maybe_clean_or_replace_eh_stmt/gimple_purge_dead_eh_edges
> would not be called for that statement.
> This adds these calls to that path.
>
> Bootstrapped and tested on x86_64-linux-gnu with no regressions.
>
> Ok? For the trunk, 14, 13 and 12 branches?

I wonder if this can be somehow integrated better with the existing

          old_stmt = stmt;
          stmt = gsi_stmt (i);
          update_stmt (stmt);

          if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)
              && gimple_purge_dead_eh_edges (bb))
            cfg_changed = true;

which frankly looks odd - update_stmt shouldn't ever change stmt.  Maybe
moving the old_stmt assign before the switch works?

>         PR tree-optimization/116601
>
> gcc/ChangeLog:
>
>         * tree-ssa-ccp.cc (pass_fold_builtins::execute): Cleanup eh
>         after optimize_memcpy on a mem statement.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/torture/except-2.C: New test.
>
> Signed-off-by: Andrew Pinski <[email protected]>
> ---
>  gcc/testsuite/g++.dg/torture/except-2.C | 18 ++++++++++++++++++
>  gcc/tree-ssa-ccp.cc                     | 11 +++++++++--
>  2 files changed, 27 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/torture/except-2.C
>
> diff --git a/gcc/testsuite/g++.dg/torture/except-2.C 
> b/gcc/testsuite/g++.dg/torture/except-2.C
> new file mode 100644
> index 00000000000..d896937a118
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/torture/except-2.C
> @@ -0,0 +1,18 @@
> +// { dg-do compile }
> +// { dg-additional-options "-fexceptions -fnon-call-exceptions" }
> +// PR tree-optimization/116601
> +
> +struct RefitOption {
> +  char subtype;
> +  int string;
> +} n;
> +void h(RefitOption);
> +void k(RefitOption *__val)
> +{
> +  try {
> +    *__val = RefitOption{};
> +    RefitOption __trans_tmp_2 = *__val;
> +    h(__trans_tmp_2);
> +  }
> +  catch(...){}
> +}
> diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
> index 44711018e0e..3cd385f476b 100644
> --- a/gcc/tree-ssa-ccp.cc
> +++ b/gcc/tree-ssa-ccp.cc
> @@ -4325,8 +4325,15 @@ pass_fold_builtins::execute (function *fun)
>            if (gimple_code (stmt) != GIMPLE_CALL)
>             {
>               if (gimple_assign_load_p (stmt) && gimple_store_p (stmt))
> -               optimize_memcpy (&i, gimple_assign_lhs (stmt),
> -                                gimple_assign_rhs1 (stmt), NULL_TREE);
> +               {
> +                 optimize_memcpy (&i, gimple_assign_lhs (stmt),
> +                                  gimple_assign_rhs1 (stmt), NULL_TREE);
> +                 old_stmt = stmt;
> +                 stmt = gsi_stmt (i);
> +                 if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)
> +                     && gimple_purge_dead_eh_edges (bb))
> +                   cfg_changed = true;
> +               }
>               gsi_next (&i);
>               continue;
>             }
> --
> 2.43.0
>

Reply via email to