From dede82f21ba8b569ad0f5538a0c00216ea71d2b4 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Mon, 14 Oct 2019 06:43:03 +0000 Subject: [PATCH] Normalize unsigned ~[0,0] into [1,MAX]. From-SVN: r276949 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/evrp4.c | 2 +- gcc/tree-vrp.c | 8 ++++---- gcc/tree-vrp.h | 27 +++++++++++++++++---------- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 053ef6c84cb..cf359bf5835 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-10-14 Aldy Hernandez + + * tree-vrp.c (value_range_base::set): Normalize unsigned ~[0,0] + into [1,MAX]. + * tree-vrp.h (value_range_base::nonzero_p): Adjust for unsigned + non-zero being represented as [1,MAX]. + 2019-10-14 Xiong Hu Luo * tree-sra.c (dump_access): Add missing braces. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c14075b80c3..fbc3d27f7a3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-14 Aldy Hernandez + + * gcc.dg/tree-ssa/evrp4.c: Adjust for unsigned non-zero being + [1,MAX]. + 2019-10-13 Iain Sandoe * gcc.target/i386/indirect-thunk-1.c: Allow 'l' or 'L' in 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 -- 2.30.2