https://gcc.gnu.org/g:1b70ccc1cec6a80b5415006183970e53114ca312

commit r17-697-g1b70ccc1cec6a80b5415006183970e53114ca312
Author: Daniel Barboza <[email protected]>
Date:   Sat Jan 17 16:01:51 2026 -0300

    fold-const.cc: remove strict_overflow_p flag from tree_single_nonnegative_p
    
    Similar to the previous patches: remove the strict_overflow_p flag to
    allow us to remove the fold_overflow_warn() from the parent function
    tree_single_nonnegative_warnv_p.
    
    The changes done in fold-const.cc caused a ripple effect on
    gimple-fold.cc, where we ended up doing similar changes to
    gimple_assign_nonnegative_warnv_p and gimple_phi_nonnegative_warnv_p.
    
    gcc/ChangeLog:
    
            * fold-const.cc (tree_single_nonnegative_warnv_p): Renamed to
            tree_single_nonnegative_p.
            (tree_single_nonnegative_p): Removed strict_overflow_p flag.
            (tree_expr_nonnegative_warnv_p): Removed strict_overflow_p flag
            from tree_single_nonnegative_p call.
            * fold-const.h (tree_single_nonnegative_warnv_p): Renamed to
            tree_single_nonnegative_p.
            (tree_single_nonnegative_p): Removed strict_overflow_p flag.
            * gimple-fold.cc (gimple_assign_nonnegative_warnv_p): Renamed to
            gimple_assign_nonnegative_p.
            (gimple_assign_nonnegative_p): Removed strict_overflow_p flag.
            (gimple_phi_nonnegative_warnv_p): Renamed to
            gimple_phi_nonnegative_p.
            (gimple_phi_nonnegative_p): Removed strict_overflow_p flag.
            (gimple_stmt_nonnegative_warnv_p): Removed strict_overflow_p
            flag from gimple_phi_nonnegative_p and gimple_assign_nonnegative_p
            calls.

Diff:
---
 gcc/fold-const.cc  | 17 ++++++++++-------
 gcc/fold-const.h   |  2 +-
 gcc/gimple-fold.cc | 26 +++++++++-----------------
 3 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 50f3f9fb58df..dce6a288529d 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -14793,17 +14793,20 @@ tree_binary_nonnegative_p (enum tree_code code, tree 
type, tree op0,
   return false;
 }
 
-/* Return true if T is known to be non-negative.  If the return
-   value is based on the assumption that signed overflow is undefined,
-   set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+/* Return true if T is known to be non-negative.
+   DEPTH is the current nesting depth of the query.  */
 
 bool
-tree_single_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth)
+tree_single_nonnegative_p (tree t, int depth)
 {
   if (TYPE_UNSIGNED (TREE_TYPE (t)))
     return true;
 
+  /* The RECURSE () macro counts with a strict_overflow_p bool
+     pointer being declared beforehand.  */
+  bool val = false;
+  bool *strict_overflow_p = &val;
+
   switch (TREE_CODE (t))
     {
     case INTEGER_CST:
@@ -15131,7 +15134,7 @@ tree_expr_nonnegative_warnv_p (tree t, bool 
*strict_overflow_p, int depth)
     case tcc_constant:
     case tcc_declaration:
     case tcc_reference:
-      return tree_single_nonnegative_warnv_p (t, strict_overflow_p, depth);
+      return tree_single_nonnegative_p (t, depth);
 
     default:
       break;
@@ -15159,7 +15162,7 @@ tree_expr_nonnegative_warnv_p (tree t, bool 
*strict_overflow_p, int depth)
     case ADDR_EXPR:
     case WITH_SIZE_EXPR:
     case SSA_NAME:
-      return tree_single_nonnegative_warnv_p (t, strict_overflow_p, depth);
+      return tree_single_nonnegative_p (t, depth);
 
     default:
       return tree_invalid_nonnegative_warnv_p (t, strict_overflow_p, depth);
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index 8f5d5b69982b..bc2d619e3d75 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -167,7 +167,7 @@ extern bool tree_binary_nonzero_p (enum tree_code, tree, 
tree, tree op1);
 extern bool tree_single_nonzero_p (tree);
 extern bool tree_unary_nonnegative_p (enum tree_code, tree, tree, int);
 extern bool tree_binary_nonnegative_p (enum tree_code, tree, tree, tree, int);
-extern bool tree_single_nonnegative_warnv_p (tree, bool *, int);
+extern bool tree_single_nonnegative_p (tree, int);
 extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree,
                                           bool *, int);
 
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 8a06acd8c1f1..06a362354d83 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -11436,13 +11436,10 @@ gimple_build_round_up (gimple_stmt_iterator *gsi,
 }
 
 /* Return true if the result of assignment STMT is known to be non-negative.
-   If the return value is based on the assumption that signed overflow is
-   undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+   DEPTH is the current nesting depth of the query.  */
 
 static bool
-gimple_assign_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
-                                  int depth)
+gimple_assign_nonnegative_p (gimple *stmt, int depth)
 {
   enum tree_code code = gimple_assign_rhs_code (stmt);
   tree type = TREE_TYPE (gimple_assign_lhs (stmt));
@@ -11462,8 +11459,8 @@ gimple_assign_nonnegative_warnv_p (gimple *stmt, bool 
*strict_overflow_p,
     case GIMPLE_TERNARY_RHS:
       return false;
     case GIMPLE_SINGLE_RHS:
-      return tree_single_nonnegative_warnv_p (gimple_assign_rhs1 (stmt),
-                                             strict_overflow_p, depth);
+      return tree_single_nonnegative_p (gimple_assign_rhs1 (stmt),
+                                       depth);
     case GIMPLE_INVALID_RHS:
       break;
     }
@@ -11492,18 +11489,15 @@ gimple_call_nonnegative_warnv_p (gimple *stmt, bool 
*strict_overflow_p,
 }
 
 /* Return true if return value of call STMT is known to be non-negative.
-   If the return value is based on the assumption that signed overflow is
-   undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+   DEPTH is the current nesting depth of the query.  */
 
 static bool
-gimple_phi_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
-                               int depth)
+gimple_phi_nonnegative_p (gimple *stmt, int depth)
 {
   for (unsigned i = 0; i < gimple_phi_num_args (stmt); ++i)
     {
       tree arg = gimple_phi_arg_def (stmt, i);
-      if (!tree_single_nonnegative_warnv_p (arg, strict_overflow_p, depth + 1))
+      if (!tree_single_nonnegative_p (arg, depth + 1))
        return false;
     }
   return true;
@@ -11530,14 +11524,12 @@ gimple_stmt_nonnegative_warnv_p (gimple *stmt, bool 
*strict_overflow_p,
   switch (gimple_code (stmt))
     {
     case GIMPLE_ASSIGN:
-      return gimple_assign_nonnegative_warnv_p (stmt, strict_overflow_p,
-                                               depth);
+      return gimple_assign_nonnegative_p (stmt, depth);
     case GIMPLE_CALL:
       return gimple_call_nonnegative_warnv_p (stmt, strict_overflow_p,
                                              depth);
     case GIMPLE_PHI:
-      return gimple_phi_nonnegative_warnv_p (stmt, strict_overflow_p,
-                                            depth);
+      return gimple_phi_nonnegative_p (stmt, depth);
     default:
       return false;
     }

Reply via email to