On Tue, Sep 23, 2025 at 7:09 PM Andrew Pinski
<[email protected]> wrote:
>
> This moves the removal of the ASSUME internal function to gimple fold.
> The only thing is fab for -Og support until fab is removed either needs to 
> stay
> or changed over to a fold_stmt. I decided to change over to a fold_stmt for
> internal function calls. I am almost positive this won't change much either 
> way.

For -Og we should be able to set PROP_last_full_fold before CCP?

> Bootstrapped and tested on x86_64-linux-gnu.
>
>         PR tree-optimization/121762
> gcc/ChangeLog:
>
>         * gimple-fold.cc (gimple_fold_call): Remove ASSUME internal function
>         calls when PROP_last_full_fold is set.
>         * tree-ssa-ccp.cc (pass_fold_builtins::execute): Handling folding
>         of all internal functions.
>
> Signed-off-by: Andrew Pinski <[email protected]>
> ---
>  gcc/gimple-fold.cc  |  6 ++++++
>  gcc/tree-ssa-ccp.cc | 29 +++++++++++++++++++++++++++--
>  2 files changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index 403fbe09102..84eb998d764 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -5883,6 +5883,12 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool 
> inplace)
>        tree overflow = NULL_TREE;
>        switch (gimple_call_internal_fn (stmt))
>         {
> +       case IFN_ASSUME:
> +         /* Remove .ASSUME calls during the last fold since it is no
> +            longer needed.  */
> +         if (cfun->curr_properties & PROP_last_full_fold)
> +           replace_call_with_value (gsi, NULL_TREE);
> +         break;
>         case IFN_BUILTIN_EXPECT:
>           result = fold_builtin_expect (gimple_location (stmt),
>                                         gimple_call_arg (stmt, 0),
> diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
> index 070289ca9f0..d2c133345cd 100644
> --- a/gcc/tree-ssa-ccp.cc
> +++ b/gcc/tree-ssa-ccp.cc
> @@ -4297,9 +4297,34 @@ pass_fold_builtins::execute (function *fun)
>
>           callee = gimple_call_fndecl (stmt);
>           if (!callee
> -             && gimple_call_internal_p (stmt, IFN_ASSUME))
> +             && gimple_call_internal_p (stmt))
>             {
> -             gsi_remove (&i, true);
> +             if (!fold_stmt (&i))
> +               {
> +                 gsi_next (&i);
> +                 continue;
> +               }
> +             if (dump_file && (dump_flags & TDF_DETAILS))
> +               {
> +                 fprintf (dump_file, "Simplified\n  ");
> +                 print_gimple_stmt (dump_file, stmt, 0, dump_flags);
> +               }
> +
> +             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;
> +
> +             if (dump_file && (dump_flags & TDF_DETAILS))
> +               {
> +                 fprintf (dump_file, "to\n  ");
> +                 print_gimple_stmt (dump_file, stmt, 0, dump_flags);
> +                 fprintf (dump_file, "\n");
> +               }
> +             gsi_next (&i);
>               continue;
>             }
>           if (!callee || !fndecl_built_in_p (callee, BUILT_IN_NORMAL))
> --
> 2.43.0
>

Reply via email to