Allow non-null adjustments for pointers even when there is a known range.
authorAldy Hernandez <aldyh@redhat.com>
Thu, 22 Jul 2021 14:03:53 +0000 (16:03 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Thu, 22 Jul 2021 15:29:07 +0000 (17:29 +0200)
Fix non_null_ref::adjust_range so it always adjust ranges, not just
varying ranges.  This will allow pointers that have a range, but are not
necessarily non-null, to be adjusted.

gcc/ChangeLog:

* gimple-range-cache.cc (non_null_ref::adjust_range): Replace
varying_p check for null/non-null check.

gcc/gimple-range-cache.cc

index 23597ad..265a64b 100644 (file)
@@ -89,12 +89,17 @@ bool
 non_null_ref::adjust_range (irange &r, tree name, basic_block bb,
                            bool search_dom)
 {
-  // Check if pointers have any non-null dereferences.  Non-call
-  // exceptions mean we could throw in the middle of the block, so just
-  // punt for now on those.
-  if (!cfun->can_throw_non_call_exceptions
-      && r.varying_p ()
-      && non_null_deref_p (name, bb, search_dom))
+  // Non-call exceptions mean we could throw in the middle of the
+  // block, so just punt on those for now.
+  if (cfun->can_throw_non_call_exceptions)
+    return false;
+
+  // We only care about the null / non-null property of pointers.
+  if (!POINTER_TYPE_P (TREE_TYPE (name)) || r.zero_p () || r.nonzero_p ())
+    return false;
+
+  // Check if pointers have any non-null dereferences.
+  if (non_null_deref_p (name, bb, search_dom))
     {
       int_range<2> nz;
       nz.set_nonzero (TREE_TYPE (name));