[PATCH 2/4] Use !contains_zero_p for known nonzero tests instead of nonzero_p.

Aldy Hernandez <[email protected]> Wed, 5 Aug 2026 16:17:23 +0200
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
These callers ask whether a range excludes zero, which nonzero_p ()
only approximated (i.e. it is false for e.g. [1, 5]).

Tested on ppc64le Linux.

gcc/ChangeLog:

	* gimple-range-path.cc (path_range_query::adjust_for_non_null_uses):
	Use !contains_zero_p instead of nonzero_p.
	* tree-ssa-structalias.cc (find_what_p_points_to): Likewise.
	* tree-ssanames.cc (set_range_info): Likewise.
	* tree-vrp.cc (execute_ranger_vrp): Likewise.

gcc/analyzer/ChangeLog:

	* region-model.cc (region_model::eval_condition): Likewise.
---
 gcc/analyzer/region-model.cc | 2 +-
 gcc/gimple-range-path.cc     | 2 +-
 gcc/tree-ssa-structalias.cc  | 2 +-
 gcc/tree-ssanames.cc         | 2 +-
 gcc/tree-vrp.cc              | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 8addf1d9a07..f385e008fa7 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -5161,7 +5161,7 @@ region_model::eval_condition (const svalue *lhs,
 		  {
 		    if (out.zero_p ())
 		      return tristate::TS_FALSE;
-		    if (out.nonzero_p ())
+		    if (!out.contains_zero_p ())
 		      return tristate::TS_TRUE;
 		  }
 	      }
diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index a8d137741f1..8a89da3dda3 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -460,7 +460,7 @@ path_range_query::adjust_for_non_null_uses (basic_block bb)
 
       if (get_cache (r, name))
 	{
-	  if (r.nonzero_p ())
+	  if (!r.contains_zero_p ())
 	    continue;
 	}
       else
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 30f911e2c72..76fb3600e74 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -934,7 +934,7 @@ find_what_p_points_to (tree fndecl, tree p)
   varinfo_t vi;
   prange vr;
   get_range_query (DECL_STRUCT_FUNCTION (fndecl))->range_of_expr (vr, p);
-  bool nonnull = vr.nonzero_p ();
+  bool nonnull = !vr.contains_zero_p ();
 
   /* For parameters, get at the points-to set for the actual parm
      decl.  */
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index d2ebb49909f..9ad860df65a 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -429,7 +429,7 @@ set_range_info (tree name, const vrange &r)
     {
       struct ptr_info_def *pi = get_ptr_info (name);
       // If R is nonnull and pi is not, set nonnull.
-      if (r.nonzero_p () && (!pi || pi->pt.null))
+      if (!r.contains_zero_p () && (!pi || pi->pt.null))
 	set_ptr_nonnull (name);
       else
 	return false;
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 49eeedb8266..da65d67b405 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -1139,7 +1139,7 @@ execute_ranger_vrp (struct function *fun, bool final_p)
 	{
 	  ipa_record_return_value_range (return_range);
 	  if (POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl)))
-	      && return_range.nonzero_p ()
+	      && !return_range.contains_zero_p ()
 	      && cgraph_node::get (current_function_decl)
 			->add_detected_attribute ("returns_nonnull"))
 	    warn_function_returns_nonnull (current_function_decl);
-- 
2.47.3