diff --git a/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c b/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c index ebb87ed38b0..ba2f6b9b430 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c @@ -17,4 +17,4 @@ int bar (struct st *s) foo (&s->a); } -/* { dg-final { scan-tree-dump "\~\\\[0B, 0B\\\]" "evrp" } } */ +/* { dg-final { scan-tree-dump "\\\[1B, -1B\\\]" "evrp" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index d69cfb107cb..cffa0508340 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -800,13 +800,13 @@ value_range_base::set (enum value_range_kind kind, tree min, tree max) kind = VR_RANGE; } else if (is_min - /* As a special exception preserve non-null ranges. */ - && !(TYPE_UNSIGNED (TREE_TYPE (min)) - && integer_zerop (max))) + /* Allow non-zero pointers to be normalized to [1,MAX]. */ + || (POINTER_TYPE_P (TREE_TYPE (min)) + && integer_zerop (min))) { tree one = build_int_cst (TREE_TYPE (max), 1); min = int_const_binop (PLUS_EXPR, max, one); - max = vrp_val_max (TREE_TYPE (max)); + max = vrp_val_max (TREE_TYPE (max), true); kind = VR_RANGE; } else if (is_max) diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index a3f9e90699d..4bfdfeb8f79 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -245,16 +245,6 @@ value_range_base::zero_p () const && integer_zerop (m_max)); } -/* Return TRUE if range is nonzero. */ - -inline bool -value_range_base::nonzero_p () const -{ - return (m_kind == VR_ANTI_RANGE - && integer_zerop (m_min) - && integer_zerop (m_max)); -} - extern void dump_value_range (FILE *, const value_range *); extern void dump_value_range (FILE *, const value_range_base *); @@ -322,6 +312,23 @@ extern tree get_single_symbol (tree, bool *, tree *); extern void maybe_set_nonzero_bits (edge, tree); extern value_range_kind determine_value_range (tree, wide_int *, wide_int *); +/* Return TRUE if range is nonzero. */ + +inline bool +value_range_base::nonzero_p () const +{ + if (m_kind == VR_ANTI_RANGE + && !TYPE_UNSIGNED (type ()) + && integer_zerop (m_min) + && integer_zerop (m_max)) + return true; + + return (m_kind == VR_RANGE + && TYPE_UNSIGNED (type ()) + && integer_onep (m_min) + && vrp_val_is_max (m_max, true)); +} + /* Return TRUE if *VR includes the value zero. */ inline bool