aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2018-11-09 09:52:32 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2018-11-09 09:52:32 +0000
commitc89af696c372d94688b06618a226ed49235ad212 (patch)
treee5607fc7bf18b658cf1c1f072b529f36de8df0d0 /gcc
parent15e109b35dd461f2d6af85b861c4c71ea4478cb4 (diff)
downloadgcc-c89af696c372d94688b06618a226ed49235ad212.zip
gcc-c89af696c372d94688b06618a226ed49235ad212.tar.gz
gcc-c89af696c372d94688b06618a226ed49235ad212.tar.bz2
gimple-fold.c (size_must_be_zero_p): Use value_range API instead of performing ad-hoc calculations.
* gimple-fold.c (size_must_be_zero_p): Use value_range API instead of performing ad-hoc calculations. * tree-ssanames.c (set_range_info): New overloaded function accepting value_range &. (get_range_info): Same. * tree-ssanames.h (set_range_info_raw): Remove. (set_range_info): New prototype. (get_range_info): Same. * tree-vrp.h (value_range::null_p): Rename to zero_p. * tree-vrp.c (value_range::null_p): Same. From-SVN: r265952
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/gimple-fold.c21
-rw-r--r--gcc/tree-ssanames.c30
-rw-r--r--gcc/tree-ssanames.h5
-rw-r--r--gcc/tree-vrp.c2
-rw-r--r--gcc/tree-vrp.h4
6 files changed, 57 insertions, 18 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4612ddf..0389ead 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,16 @@
+2018-11-08 Aldy Hernandez <aldyh@redhat.com>
+
+ * gimple-fold.c (size_must_be_zero_p): Use value_range API instead
+ of performing ad-hoc calculations.
+ * tree-ssanames.c (set_range_info): New overloaded function
+ accepting value_range &.
+ (get_range_info): Same.
+ * tree-ssanames.h (set_range_info_raw): Remove.
+ (set_range_info): New prototype.
+ (get_range_info): Same.
+ * tree-vrp.h (value_range::null_p): Rename to zero_p.
+ * tree-vrp.c (value_range::null_p): Same.
+
2018-11-09 Jan Hubicka <jh@suse.cz>
* tree.c (fld_type_variant_equal_p): Test user align flag.
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 5468b60..67c8cfa 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -635,9 +635,8 @@ var_decl_component_p (tree var)
&& TREE_CODE (TREE_OPERAND (inner, 0)) == ADDR_EXPR));
}
-/* If the SIZE argument representing the size of an object is in a range
- of values of which exactly one is valid (and that is zero), return
- true, otherwise false. */
+/* Return TRUE if the SIZE argument, representing the size of an
+ object, is in a range of values of which exactly zero is valid. */
static bool
size_must_be_zero_p (tree size)
@@ -648,21 +647,19 @@ size_must_be_zero_p (tree size)
if (TREE_CODE (size) != SSA_NAME || !INTEGRAL_TYPE_P (TREE_TYPE (size)))
return false;
- wide_int min, max;
- enum value_range_kind rtype = get_range_info (size, &min, &max);
- if (rtype != VR_ANTI_RANGE)
- return false;
-
tree type = TREE_TYPE (size);
int prec = TYPE_PRECISION (type);
- wide_int wone = wi::one (prec);
-
/* Compute the value of SSIZE_MAX, the largest positive value that
can be stored in ssize_t, the signed counterpart of size_t. */
wide_int ssize_max = wi::lshift (wi::one (prec), prec - 1) - 1;
-
- return wi::eq_p (min, wone) && wi::geu_p (max, ssize_max);
+ value_range valid_range (VR_RANGE,
+ build_int_cst (type, 0),
+ wide_int_to_tree (type, ssize_max));
+ value_range vr;
+ get_range_info (size, vr);
+ vr.intersect (&valid_range);
+ return vr.zero_p ();
}
/* Fold function call to builtin mem{{,p}cpy,move}. Try to detect and
diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c
index ff906e8..a2c2efb 100644
--- a/gcc/tree-ssanames.c
+++ b/gcc/tree-ssanames.c
@@ -398,6 +398,15 @@ set_range_info (tree name, enum value_range_kind range_type,
set_range_info_raw (name, range_type, min, max);
}
+/* Store range information for NAME from a value_range. */
+
+void
+set_range_info (tree name, const value_range &vr)
+{
+ wide_int min = wi::to_wide (vr.min ());
+ wide_int max = wi::to_wide (vr.max ());
+ set_range_info (name, vr.kind (), min, max);
+}
/* Gets range information MIN, MAX and returns enum value_range_kind
corresponding to tree ssa_name NAME. enum value_range_kind returned
@@ -421,6 +430,27 @@ get_range_info (const_tree name, wide_int *min, wide_int *max)
return SSA_NAME_RANGE_TYPE (name);
}
+/* Gets range information corresponding to ssa_name NAME and stores it
+ in a value_range VR. Returns the value_range_kind. */
+
+enum value_range_kind
+get_range_info (const_tree name, value_range &vr)
+{
+ tree min, max;
+ wide_int wmin, wmax;
+ enum value_range_kind kind = get_range_info (name, &wmin, &wmax);
+
+ if (kind == VR_VARYING || kind == VR_UNDEFINED)
+ min = max = NULL;
+ else
+ {
+ min = wide_int_to_tree (TREE_TYPE (name), wmin);
+ max = wide_int_to_tree (TREE_TYPE (name), wmax);
+ }
+ vr = value_range (kind, min, max);
+ return kind;
+}
+
/* Set nonnull attribute to pointer NAME. */
void
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index 18a001a..a5ff14e 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -69,12 +69,11 @@ struct GTY ((variable_size)) range_info_def {
/* Sets the value range to SSA. */
extern void set_range_info (tree, enum value_range_kind, const wide_int_ref &,
const wide_int_ref &);
-extern void set_range_info_raw (tree, enum value_range_kind,
- const wide_int_ref &,
- const wide_int_ref &);
+extern void set_range_info (tree, const value_range &);
/* Gets the value range from SSA. */
extern enum value_range_kind get_range_info (const_tree, wide_int *,
wide_int *);
+extern enum value_range_kind get_range_info (const_tree, value_range &);
extern void set_nonzero_bits (tree, const wide_int_ref &);
extern wide_int get_nonzero_bits (const_tree);
extern bool ssa_name_has_boolean_range (tree);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 17b0b6c..e45d788 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -743,7 +743,7 @@ vrp_bitmap_equal_p (const_bitmap b1, const_bitmap b2)
static inline bool
range_is_null (const value_range *vr)
{
- return vr->null_p ();
+ return vr->zero_p ();
}
static inline bool
diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h
index c251329..3c870d5 100644
--- a/gcc/tree-vrp.h
+++ b/gcc/tree-vrp.h
@@ -63,7 +63,7 @@ class GTY((for_user)) value_range
/* Misc methods. */
tree type () const;
- bool null_p () const;
+ bool zero_p () const;
bool may_contain_p (tree) const;
bool singleton_p (tree *result = NULL) const;
void deep_copy (const value_range *);
@@ -150,7 +150,7 @@ value_range::undefined_p () const
/* Return TRUE if range is the constant zero. */
inline bool
-value_range::null_p () const
+value_range::zero_p () const
{
return (m_kind == VR_RANGE
&& integer_zerop (m_min)