]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fab/gimple-fold: Move removal of ASSUME internal function to gimple fold [PR121762]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 23 Sep 2025 05:25:29 +0000 (22:25 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 3 Oct 2025 14:18:03 +0000 (07:18 -0700)
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 <andrew.pinski@oss.qualcomm.com>
gcc/gimple-fold.cc
gcc/tree-ssa-ccp.cc

index 37ca0853ec82a5630f1a2edebbc8d432698d43cf..a12fb5e8eab117da6e8d1199f94e3b4e96c70565 100644 (file)
@@ -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),
index c9ffd2af85c29249f2b590337f0bbcbff62aa180..6d9cbd82d07e072ad8382b43a9e303ff6b8389e8 100644 (file)
@@ -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))