From 3eadb2d22a65bf146cd33566c89f6b3c27dc8d23 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Mon, 22 Sep 2025 22:25:29 -0700 Subject: [PATCH] fab/gimple-fold: Move removal of ASSUME internal function to gimple fold [PR121762] 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. 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 --- 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 37ca0853ec8..a12fb5e8eab 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -5886,6 +5886,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 c9ffd2af85c..6d9cbd82d07 100644 --- a/gcc/tree-ssa-ccp.cc +++ b/gcc/tree-ssa-ccp.cc @@ -4278,9 +4278,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.47.3