[PATCH 04/13] fold-const.cc: remove strict_overflow_p from tree_binary_nonzero_warnv_p

Daniel Barboza daniel.barboza@oss.qualcomm.com
Sat Jan 17 19:01:45 GMT 2026


This helper is called by tree_expr_nonzero_warnv_p(), a helper that is
gating a call to fold_overflow_warning() that we want to eliminate.

The helper is renamed to remove the "warn" from its name since it
doesn't throw or set any overflow warnings anymore.

gcc/ChangeLog:

	* fold-const.cc (tree_expr_nonzero_warnv_p): Removed
	strict_overflow_p flag from tree_binary_nonzero_p call.
	(tree_binary_nonzero_warnv_p): Renamed to tree_binary_nonzero_p.
	(tree_binary_nonzero_p): Removed strict_overflow_p flag.
	* fold-const.h (tree_binary_nonzero_warnv_p): Renamed to
	tree_binary_nonzero_p.
	(tree_binary_nonzero_p): Removed strict_overflow_p flag.
---
 gcc/fold-const.cc | 66 ++++++++++++++---------------------------------
 gcc/fold-const.h  |  3 +--
 2 files changed, 20 insertions(+), 49 deletions(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index d97ed7e48b6..b4592016b21 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -10816,10 +10816,9 @@ tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p)
       return tree_unary_nonzero_p (code, type, TREE_OPERAND (t, 0));
     case tcc_binary:
     case tcc_comparison:
-      return tree_binary_nonzero_warnv_p (code, type,
-					       TREE_OPERAND (t, 0),
-					       TREE_OPERAND (t, 1),
-					       strict_overflow_p);
+      return tree_binary_nonzero_p (code, type,
+				    TREE_OPERAND (t, 0),
+				    TREE_OPERAND (t, 1));
     case tcc_constant:
     case tcc_declaration:
     case tcc_reference:
@@ -10837,10 +10836,9 @@ tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p)
     case TRUTH_AND_EXPR:
     case TRUTH_OR_EXPR:
     case TRUTH_XOR_EXPR:
-      return tree_binary_nonzero_warnv_p (code, type,
-					       TREE_OPERAND (t, 0),
-					       TREE_OPERAND (t, 1),
-					       strict_overflow_p);
+      return tree_binary_nonzero_p (code, type,
+				    TREE_OPERAND (t, 0),
+				    TREE_OPERAND (t, 1));
 
     case COND_EXPR:
     case CONSTRUCTOR:
@@ -15256,19 +15254,12 @@ tree_unary_nonzero_p (enum tree_code code, tree type, tree op0)
 
 /* Return true when (CODE OP0 OP1) is an address and is known to be nonzero.
    For floating point we further ensure that T is not denormal.
-   Similar logic is present in nonzero_address in rtlanal.h.
-
-   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.  */
+   Similar logic is present in nonzero_address in rtlanal.h.  */
 
 bool
-tree_binary_nonzero_warnv_p (enum tree_code code,
-			     tree type,
-			     tree op0,
-			     tree op1, bool *strict_overflow_p)
+tree_binary_nonzero_p (enum tree_code code, tree type, tree op0, tree op1)
 {
-  bool sub_strict_overflow_p;
+  bool sub_strict_overflow_p = false;
   switch (code)
     {
     case POINTER_PLUS_EXPR:
@@ -15277,7 +15268,6 @@ tree_binary_nonzero_warnv_p (enum tree_code code,
 	{
 	  /* With the presence of negative values it is hard
 	     to say something.  */
-	  sub_strict_overflow_p = false;
 	  if (!tree_expr_nonnegative_warnv_p (op0,
 					      &sub_strict_overflow_p)
 	      || !tree_expr_nonnegative_warnv_p (op1,
@@ -15288,9 +15278,9 @@ tree_binary_nonzero_warnv_p (enum tree_code code,
 	     overflows, on a twos-complement machine the sum of two
 	     nonnegative numbers can never be zero.  */
 	  return (tree_expr_nonzero_warnv_p (op0,
-					     strict_overflow_p)
+					     &sub_strict_overflow_p)
 		  || tree_expr_nonzero_warnv_p (op1,
-						strict_overflow_p));
+						&sub_strict_overflow_p));
 	}
       break;
 
@@ -15298,26 +15288,14 @@ tree_binary_nonzero_warnv_p (enum tree_code code,
       if (TYPE_OVERFLOW_UNDEFINED (type))
 	{
 	  if (tree_expr_nonzero_warnv_p (op0,
-					 strict_overflow_p)
+					 &sub_strict_overflow_p)
 	      && tree_expr_nonzero_warnv_p (op1,
-					    strict_overflow_p))
-	    {
-	      *strict_overflow_p = true;
-	      return true;
-	    }
+					    &sub_strict_overflow_p))
+	    return true;
 	}
       break;
 
     case MIN_EXPR:
-      sub_strict_overflow_p = false;
-      if (tree_expr_nonzero_warnv_p (op0,
-				     &sub_strict_overflow_p)
-	  && tree_expr_nonzero_warnv_p (op1,
-					&sub_strict_overflow_p))
-	{
-	  if (sub_strict_overflow_p)
-	    *strict_overflow_p = true;
-	}
       break;
 
     case MAX_EXPR:
@@ -15325,35 +15303,29 @@ tree_binary_nonzero_warnv_p (enum tree_code code,
       if (tree_expr_nonzero_warnv_p (op0,
 				     &sub_strict_overflow_p))
 	{
-	  if (sub_strict_overflow_p)
-	    *strict_overflow_p = true;
 
 	  /* When both operands are nonzero, then MAX must be too.  */
 	  if (tree_expr_nonzero_warnv_p (op1,
-					 strict_overflow_p))
+					 &sub_strict_overflow_p))
 	    return true;
 
 	  /* MAX where operand 0 is positive is positive.  */
 	  return tree_expr_nonnegative_warnv_p (op0,
-					       strict_overflow_p);
+						&sub_strict_overflow_p);
 	}
       /* MAX where operand 1 is positive is positive.  */
       else if (tree_expr_nonzero_warnv_p (op1,
 					  &sub_strict_overflow_p)
 	       && tree_expr_nonnegative_warnv_p (op1,
 						 &sub_strict_overflow_p))
-	{
-	  if (sub_strict_overflow_p)
-	    *strict_overflow_p = true;
-	  return true;
-	}
+	return true;
       break;
 
     case BIT_IOR_EXPR:
       return (tree_expr_nonzero_warnv_p (op1,
-					 strict_overflow_p)
+					 &sub_strict_overflow_p)
 	      || tree_expr_nonzero_warnv_p (op0,
-					    strict_overflow_p));
+					    &sub_strict_overflow_p));
 
     default:
       break;
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index 0e6b3306034..7bd2e31fff0 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -163,8 +163,7 @@ extern enum tree_code invert_tree_comparison (enum tree_code, bool);
 extern bool inverse_conditions_p (const_tree, const_tree);
 
 extern bool tree_unary_nonzero_p (enum tree_code, tree, tree);
-extern bool tree_binary_nonzero_warnv_p (enum tree_code, tree, tree, tree op1,
-                                         bool *);
+extern bool tree_binary_nonzero_p (enum tree_code, tree, tree, tree op1);
 extern bool tree_single_nonzero_warnv_p (tree, bool *);
 extern bool tree_unary_nonnegative_warnv_p (enum tree_code, tree, tree,
 					    bool *, int);
-- 
2.43.0



More information about the Gcc-patches mailing list