This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [ping][PATCH][1 of 2] Add value range info to SSA_NAME for zero sign extension elimination in RTL
- From: Kugan <kugan dot vivekanandarajah at linaro dot org>
- To: Richard Biener <rguenther at suse dot de>
- Cc: Jakub Jelinek <jakub at redhat dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Ramana Radhakrishnan <ramana dot radhakrishnan at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>
- Date: Wed, 18 Sep 2013 14:06:46 +0930
- Subject: Re: [ping][PATCH][1 of 2] Add value range info to SSA_NAME for zero sign extension elimination in RTL
- Authentication-results: sourceware.org; auth=none
- References: <CAFiYyc10HBW1PX+3jAQ=yJKfTjkP-9F2DnujNhU_ZBE0xG8_uQ at mail dot gmail dot com> <5225D2E4 dot 303 at linaro dot org> <52297A5B dot 1010309 at suse dot de> <522D03B9 dot 6060201 at linaro dot org> <CAFiYyc0xYQQ9Cpsw5wVgy3zsxNppuJzyUyAg8Y4u90nKad+k8w at mail dot gmail dot com> <522E99DD dot 2080505 at linaro dot org> <alpine dot LNX dot 2 dot 00 dot 1309101432560 dot 3150 at zhemvz dot fhfr dot qr> <20130910134006 dot GZ1817 at tucnak dot redhat dot com> <52300715 dot 4080307 at linaro dot org> <alpine dot LNX dot 2 dot 00 dot 1309111101220 dot 3150 at zhemvz dot fhfr dot qr> <20130911090837 dot GM1817 at tucnak dot redhat dot com> <alpine dot LNX dot 2 dot 00 dot 1309111110400 dot 3150 at zhemvz dot fhfr dot qr> <52329E95 dot 1080501 at linaro dot org> <52368DAB dot 1040103 at linaro dot org> <alpine dot LNX dot 2 dot 00 dot 1309161552480 dot 29729 at zhemvz dot fhfr dot qr>
Thanks Richard for the review.
On 16/09/13 23:43, Richard Biener wrote:
On Mon, 16 Sep 2013, Kugan wrote:
Hi,
Updated the patch to the latest changes in trunk that splits tree.h. I also
noticed an error in printing double_int and fixed it.
Is this OK?
print_gimple_stmt (dump_file, stmt, 0,
- TDF_SLIM | (dump_flags & TDF_LINENO));
+ TDF_SLIM | TDF_RANGE | (dump_flags &
TDF_LINENO));
this should be (dump_flags & (TDF_LINENO|TDF_RANGE)) do not always
dump range info. I'd have simply re-used TDF_ALIAS (and interpret
it as SSA annotation info), adding -range in dump file modifiers
is ok with me.
+static void
+print_double_int (pretty_printer *buffer, double_int cst)
+{
+ tree node = double_int_to_tree (integer_type_node, cst);
+ if (TREE_INT_CST_HIGH (node) == 0)
+ pp_printf (buffer, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW
(node));
+ else if (TREE_INT_CST_HIGH (node) == -1
+ && TREE_INT_CST_LOW (node) != 0)
+ pp_printf (buffer, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
+ -TREE_INT_CST_LOW (node));
+ else
+ sprintf (pp_buffer (buffer)->digit_buffer,
+ HOST_WIDE_INT_PRINT_DOUBLE_HEX,
+ (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
+ (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
using sprintf here looks like a layering violation to me. You
probably want to factor out code from the INTEGER_CST handling
of tree-pretty-print.c:dump_generic_node into a pp_double_int
function in pretty-print.[ch] instead.
@@ -1628,6 +1647,27 @@ dump_gimple_phi (pretty_printer *buffer, gimple
phi, int spc, int flags)
pp_string (buffer, "# ");
}
+ if ((flags & TDF_RANGE)
+ && !POINTER_TYPE_P (TREE_TYPE (lhs))
+ && SSA_NAME_RANGE_INFO (lhs))
+ {
+ double_int min, max;
+ value_range_type range_type;
I realize the scheme is pre-existing but can you try factoring
out the dumping of SSA_NAME_PTR_INFO / SSA_NAME_RANGE_INFO into
a separate routine that can be shared by dump_gimple_phi and
pp_gimple_stmt_1?
+get_range_info (tree name, double_int &min, double_int &max,
+ enum value_range_type &range_type)
+{
+ gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
+ gcc_assert (TREE_CODE (name) == SSA_NAME);
+ range_info_def *ri = SSA_NAME_RANGE_INFO (name);
the TREE_CODE (name) == SSA_NAME assert is redundant with the
tree-checking performed by SSA_NAME_RANGE_INFO. Likewise in
the other functions.
+void
+get_range_info (tree name, double_int &min, double_int &max,
+ enum value_range_type &range_type)
I'm not sure we want to use references. Well - first time.
+ /* If min > max, it is VR_ANTI_RANGE. */
+ if (ri->min.scmp (ri->max) == 1)
+ {
I think that's wrong and needs to be conditional on TYPE_UNSIGNED
of the SSA name.
+ else if (vr_value[i]->type == VR_ANTI_RANGE)
+ {
+ /* VR_ANTI_RANGE ~[min, max] is encoded compactly as
+ [max + 1, min - 1] without additional attributes.
+ When min value > max value, we know that it is
+ VR_ANTI_RANGE; it is VR_RANGE othewise. */
+ set_range_info (name,
+ tree_to_double_int (vr_value[i]->max)
+ + double_int_one,
+ tree_to_double_int (vr_value[i]->min)
+ - double_int_one);
there is a complication for when max + 1 or min - 1 overflow - those
should be non-canonical ranges I think, but double-check this
(check set_and_canonicalize_value_range).
I have now added a check for min == 0 for unsigned type. AFAIK, For
double_int type, this is the only case we should check.
I have also made the other changes you have asked me to do. Please find
the modified patch and ChangeLog.
Bootstrapped and regtested for x86_64-unknown-linux-gnu. Is this OK.
Thanks,
Kugan
+2013-09-17 Kugan Vivekanandarajah <kuganv@linaro.org>
+
+ * gimple-pretty-print.c (dump_ssaname_info) : New function.
+ * gimple-pretty-print.c (dump_gimple_phi) : Dump range info.
+ * (pp_gimple_stmt_1) : Likewise.
+ * tree-pretty-print.c (dump_intger_cst_node) : New function.
+ * (dump_generic_node) : Call dump_intger_cst_node for INTEGER_CST.
+ * tree-ssa-alias.c (dump_alias_info) : Check pointer type.
+ * tree-ssa-copy.c (fini_copy_prop) : Check pointer type and copy
+ range info.
+ * tree-ssanames.c (make_ssa_name_fn) : Check pointer type in
+ initialize.
+ * (set_range_info) : New function.
+ * (get_range_info) : Likewise.
+ * (duplicate_ssa_name_range_info) : Likewise.
+ * (duplicate_ssa_name_fn) : Check pointer type and call correct
+ duplicate function.
+ * tree-vrp.c (vrp_finalize): Call set_range_info to upddate
+ value range of SSA_NAMEs.
+ * tree.h (SSA_NAME_PTR_INFO) : changed to access via union
+ * tree.h (SSA_NAME_RANGE_INFO) : New macro
+
+/* Type of value ranges. See value_range_d In tree-vrp.c for a
+ description of these types. */
+enum value_range_type { VR_UNDEFINED, VR_RANGE, VR_ANTI_RANGE, VR_VARYING
};
+
+/* Sets the value range to SSA. */
+void set_range_info (tree ssa, double_int min, double_int max);
+/* Gets the value range from SSA. */
+void get_range_info (tree name, double_int &min, double_int &max,
+ enum value_range_type &range_type);
put these into tree-ssanames.h please, likewise struct GTY (())
range_info_def - this is where the ptr-info stuff went very recently.
Thanks,
Richard.
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 01a1ab5..fd36247 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1600,23 +1600,17 @@ dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
}
}
-
-/* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
- The caller is responsible for calling pp_flush on BUFFER to finalize
- pretty printer. */
+/* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
+ SPC spaces of indent. */
static void
-dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
+dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
{
- size_t i;
- tree lhs = gimple_phi_result (phi);
-
- if (flags & TDF_ALIAS
- && POINTER_TYPE_P (TREE_TYPE (lhs))
- && SSA_NAME_PTR_INFO (lhs))
+ if (POINTER_TYPE_P (TREE_TYPE (node))
+ && SSA_NAME_PTR_INFO (node))
{
unsigned int align, misalign;
- struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
+ struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
pp_string (buffer, "PT = ");
pp_points_to_solution (buffer, &pi->pt);
newline_and_indent (buffer, spc);
@@ -1628,6 +1622,43 @@ dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
pp_string (buffer, "# ");
}
+ if (!POINTER_TYPE_P (TREE_TYPE (node))
+ && SSA_NAME_RANGE_INFO (node))
+ {
+ double_int min, max;
+ value_range_type range_type = get_range_info (node, &min, &max);
+
+ if (range_type == VR_VARYING)
+ pp_printf (buffer, "# RANGE VR_VARYING");
+ else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
+ {
+ pp_printf (buffer, "# RANGE ");
+ pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
+ dump_intger_cst_node (buffer,
+ double_int_to_tree (TREE_TYPE (node), min));
+ pp_printf (buffer, ", ");
+ dump_intger_cst_node (buffer,
+ double_int_to_tree (TREE_TYPE (node), max));
+ pp_printf (buffer, "]");
+ newline_and_indent (buffer, spc);
+ }
+ }
+}
+
+
+/* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
+ The caller is responsible for calling pp_flush on BUFFER to finalize
+ pretty printer. */
+
+static void
+dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
+{
+ size_t i;
+ tree lhs = gimple_phi_result (phi);
+
+ if (flags & TDF_ALIAS)
+ dump_ssaname_info (buffer, lhs, spc);
+
if (flags & TDF_RAW)
dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
gimple_phi_result (phi));
@@ -1908,27 +1939,9 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
&& gimple_has_mem_ops (gs))
dump_gimple_mem_ops (buffer, gs, spc, flags);
- if ((flags & TDF_ALIAS)
- && gimple_has_lhs (gs))
- {
- tree lhs = gimple_get_lhs (gs);
- if (TREE_CODE (lhs) == SSA_NAME
- && POINTER_TYPE_P (TREE_TYPE (lhs))
- && SSA_NAME_PTR_INFO (lhs))
- {
- unsigned int align, misalign;
- struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
- pp_string (buffer, "# PT = ");
- pp_points_to_solution (buffer, &pi->pt);
- newline_and_indent (buffer, spc);
- if (get_ptr_info_alignment (pi, &align, &misalign))
- {
- pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
- align, misalign);
- newline_and_indent (buffer, spc);
- }
- }
- }
+ if (gimple_has_lhs (gs)
+ && (flags & TDF_ALIAS))
+ dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
switch (gimple_code (gs))
{
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 69777dc..2acc379 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -43,6 +43,7 @@ struct function;
struct real_value;
struct fixed_value;
struct ptr_info_def;
+struct range_info_def;
struct die_struct;
struct pointer_set_t;
@@ -1050,8 +1051,14 @@ struct GTY(()) tree_ssa_name {
/* Statement that defines this SSA name. */
gimple def_stmt;
- /* Pointer attributes used for alias analysis. */
- struct ptr_info_def *ptr_info;
+ /* Value range information. */
+ union ssa_name_info_type {
+ /* Pointer attributes used for alias analysis. */
+ struct GTY ((tag ("0"))) ptr_info_def *ptr_info;
+ /* Value range attributes used for zero/sign extension elimination. */
+ struct GTY ((tag ("1"))) range_info_def *range_info;
+ } GTY ((desc ("%1.typed.type ?" \
+ "!POINTER_TYPE_P (TREE_TYPE ((tree)&%1)) : 2"))) info;
/* Immediate uses list for this SSA_NAME. */
struct ssa_use_operand_d imm_uses;
diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index 4c04816..1b2d1d5 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -617,6 +617,62 @@ dump_block_node (pretty_printer *buffer, tree block, int spc, int flags)
}
}
+/* Dump INTEGER_CST NODE on pretty_printer BUFFER with SPC spaces of
+ indent. FLAGS specifies details to show in the dump (see TDF_* in
+ dumpfile.h). */
+
+void
+dump_intger_cst_node (pretty_printer *buffer, tree node)
+{
+ if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
+ {
+ /* In the case of a pointer, one may want to divide by the
+ size of the pointed-to type. Unfortunately, this not
+ straightforward. The C front-end maps expressions
+
+ (int *) 5
+ int *p; (p + 5)
+
+ in such a way that the two INTEGER_CST nodes for "5" have
+ different values but identical types. In the latter
+ case, the 5 is multiplied by sizeof (int) in c-common.c
+ (pointer_int_sum) to convert it to a byte address, and
+ yet the type of the node is left unchanged. Argh. What
+ is consistent though is that the number value corresponds
+ to bytes (UNITS) offset.
+
+ NB: Neither of the following divisors can be trivially
+ used to recover the original literal:
+
+ TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
+ TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
+ pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
+ pp_string (buffer, "B"); /* pseudo-unit. */
+ }
+ else if (host_integerp (node, 0))
+ pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
+ else if (host_integerp (node, 1))
+ pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node));
+ else
+ {
+ tree val = node;
+ unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
+ HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
+
+ if (tree_int_cst_sgn (val) < 0)
+ {
+ pp_minus (buffer);
+ high = ~high + !low;
+ low = -low;
+ }
+ /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
+ systems? */
+ sprintf (pp_buffer (buffer)->digit_buffer,
+ HOST_WIDE_INT_PRINT_DOUBLE_HEX,
+ (unsigned HOST_WIDE_INT) high, low);
+ pp_string (buffer, pp_buffer (buffer)->digit_buffer);
+ }
+}
/* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of
indent. FLAGS specifies details to show in the dump (see TDF_* in
@@ -1037,56 +1093,8 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
break;
case INTEGER_CST:
- if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
- {
- /* In the case of a pointer, one may want to divide by the
- size of the pointed-to type. Unfortunately, this not
- straightforward. The C front-end maps expressions
-
- (int *) 5
- int *p; (p + 5)
-
- in such a way that the two INTEGER_CST nodes for "5" have
- different values but identical types. In the latter
- case, the 5 is multiplied by sizeof (int) in c-common.c
- (pointer_int_sum) to convert it to a byte address, and
- yet the type of the node is left unchanged. Argh. What
- is consistent though is that the number value corresponds
- to bytes (UNITS) offset.
-
- NB: Neither of the following divisors can be trivially
- used to recover the original literal:
-
- TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
- TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
- pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
- pp_string (buffer, "B"); /* pseudo-unit */
- }
- else if (host_integerp (node, 0))
- pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
- else if (host_integerp (node, 1))
- pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node));
- else
- {
- tree val = node;
- unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
- HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
-
- if (tree_int_cst_sgn (val) < 0)
- {
- pp_minus (buffer);
- high = ~high + !low;
- low = -low;
- }
- /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
- systems? */
- sprintf (pp_buffer (buffer)->digit_buffer,
- HOST_WIDE_INT_PRINT_DOUBLE_HEX,
- (unsigned HOST_WIDE_INT) high, low);
- pp_string (buffer, pp_buffer (buffer)->digit_buffer);
- }
+ dump_intger_cst_node (buffer, node);
break;
-
case REAL_CST:
/* Code copied from print_node. */
{
diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h
index 7da8000..bea4add 100644
--- a/gcc/tree-pretty-print.h
+++ b/gcc/tree-pretty-print.h
@@ -35,6 +35,7 @@ extern void pp_tree_identifier (pretty_printer *, tree);
/* In tree-pretty-print.c */
extern void print_declaration (pretty_printer *, tree, int, int);
extern int dump_generic_node (pretty_printer *, tree, int, int, bool);
+extern void dump_intger_cst_node (pretty_printer *buffer, tree node);
extern void print_generic_stmt (FILE *, tree, int);
extern void print_generic_stmt_indented (FILE *, tree, int, int);
extern void print_generic_expr (FILE *, tree, int);
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index 9a6d5f4..0ef7401 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -404,6 +404,7 @@ dump_alias_info (FILE *file)
struct ptr_info_def *pi;
if (ptr == NULL_TREE
+ || !POINTER_TYPE_P (TREE_TYPE (ptr))
|| SSA_NAME_IN_FREE_LIST (ptr))
continue;
diff --git a/gcc/tree-ssa-copy.c b/gcc/tree-ssa-copy.c
index 3197917..25a43ff 100644
--- a/gcc/tree-ssa-copy.c
+++ b/gcc/tree-ssa-copy.c
@@ -767,11 +767,19 @@ fini_copy_prop (void)
of the representative to the first solution we find if
it doesn't have one already. */
if (copy_of[i].value != var
- && TREE_CODE (copy_of[i].value) == SSA_NAME
- && POINTER_TYPE_P (TREE_TYPE (var))
- && SSA_NAME_PTR_INFO (var)
- && !SSA_NAME_PTR_INFO (copy_of[i].value))
- duplicate_ssa_name_ptr_info (copy_of[i].value, SSA_NAME_PTR_INFO (var));
+ && TREE_CODE (copy_of[i].value) == SSA_NAME)
+ {
+ if (POINTER_TYPE_P (TREE_TYPE (var))
+ && SSA_NAME_PTR_INFO (var)
+ && !SSA_NAME_PTR_INFO (copy_of[i].value))
+ duplicate_ssa_name_ptr_info (copy_of[i].value,
+ SSA_NAME_PTR_INFO (var));
+ else if (!POINTER_TYPE_P (TREE_TYPE (var))
+ && SSA_NAME_RANGE_INFO (var)
+ && !SSA_NAME_RANGE_INFO (copy_of[i].value))
+ duplicate_ssa_name_range_info (copy_of[i].value,
+ SSA_NAME_RANGE_INFO (var));
+ }
}
/* Don't do DCE if SCEV is initialized. It would destroy the scev cache. */
diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c
index e64bd65..cd19640 100644
--- a/gcc/tree-ssanames.c
+++ b/gcc/tree-ssanames.c
@@ -154,7 +154,11 @@ make_ssa_name_fn (struct function *fn, tree var, gimple stmt)
SET_SSA_NAME_VAR_OR_IDENTIFIER (t, var);
}
SSA_NAME_DEF_STMT (t) = stmt;
- SSA_NAME_PTR_INFO (t) = NULL;
+ if (POINTER_TYPE_P (TREE_TYPE (t)))
+ SSA_NAME_PTR_INFO (t) = NULL;
+ else
+ SSA_NAME_RANGE_INFO (t) = NULL;
+
SSA_NAME_IN_FREE_LIST (t) = 0;
SSA_NAME_IS_DEFAULT_DEF (t) = 0;
imm = &(SSA_NAME_IMM_USE_NODE (t));
@@ -166,6 +170,62 @@ make_ssa_name_fn (struct function *fn, tree var, gimple stmt)
return t;
}
+/* Store range information MIN, and MAX to tree ssa_name NAME. */
+
+void
+set_range_info (tree name, double_int min, double_int max)
+{
+ gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
+ range_info_def *ri = SSA_NAME_RANGE_INFO (name);
+
+ /* Allocate if not available. */
+ if (ri == NULL)
+ {
+ ri = ggc_alloc_cleared_range_info_def ();
+ SSA_NAME_RANGE_INFO (name) = ri;
+ }
+
+ /* Set the values. */
+ ri->min = min;
+ ri->max = max;
+}
+
+
+/* Gets range information MIN, MAX and returns enum value_range_type
+ corresponding to tree ssa_name NAME. enum value_range_type returned
+ is used to determine MIN and MAX are valid values. */
+
+enum value_range_type
+get_range_info (tree name, double_int *min, double_int *max)
+{
+ enum value_range_type range_type;
+ gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
+ gcc_assert (min && max);
+ range_info_def *ri = SSA_NAME_RANGE_INFO (name);
+
+ /* Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs
+ with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision. */
+ if (!ri || (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (name)))
+ > 2 * HOST_BITS_PER_WIDE_INT))
+ return VR_VARYING;
+
+ /* If min > max, it is VR_ANTI_RANGE. */
+ if (ri->min.cmp (ri->max, TYPE_UNSIGNED (TREE_TYPE (name))) == 1)
+ {
+ /* VR_ANTI_RANGE ~[min, max] is encoded as [max + 1, min - 1]. */
+ range_type = VR_ANTI_RANGE;
+ *min = ri->max + double_int_one;
+ *max = ri->min - double_int_one;
+ }
+ else
+ {
+ /* Otherwise (when min <= max), it is VR_RANGE. */
+ range_type = VR_RANGE;
+ *min = ri->min;
+ *max = ri->max;
+ }
+ return range_type;
+}
/* We no longer need the SSA_NAME expression VAR, release it so that
it may be reused.
@@ -362,6 +422,26 @@ duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info)
SSA_NAME_PTR_INFO (name) = new_ptr_info;
}
+/* Creates a duplicate of the range_info_def at RANGE_INFO for use by
+ the SSA name NAME. */
+void
+duplicate_ssa_name_range_info (tree name, struct range_info_def *range_info)
+{
+ struct range_info_def *new_range_info;
+
+ gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
+ gcc_assert (!SSA_NAME_RANGE_INFO (name));
+
+ if (!range_info)
+ return;
+
+ new_range_info = ggc_alloc_range_info_def ();
+ *new_range_info = *range_info;
+
+ SSA_NAME_RANGE_INFO (name) = new_range_info;
+}
+
+
/* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
in function FN. */
@@ -370,10 +450,20 @@ tree
duplicate_ssa_name_fn (struct function *fn, tree name, gimple stmt)
{
tree new_name = copy_ssa_name_fn (fn, name, stmt);
- struct ptr_info_def *old_ptr_info = SSA_NAME_PTR_INFO (name);
+ if (POINTER_TYPE_P (TREE_TYPE (name)))
+ {
+ struct ptr_info_def *old_ptr_info = SSA_NAME_PTR_INFO (name);
+
+ if (old_ptr_info)
+ duplicate_ssa_name_ptr_info (new_name, old_ptr_info);
+ }
+ else
+ {
+ struct range_info_def *old_range_info = SSA_NAME_RANGE_INFO (name);
- if (old_ptr_info)
- duplicate_ssa_name_ptr_info (new_name, old_ptr_info);
+ if (old_range_info)
+ duplicate_ssa_name_range_info (new_name, old_range_info);
+ }
return new_name;
}
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index 8cc3efd..9a8ea14 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -45,6 +45,15 @@ struct GTY(()) ptr_info_def
unsigned int misalign;
};
+/* Value range information for SSA_NAMEs representing non-pointer variables. */
+
+struct GTY (()) range_info_def {
+ /* Minmum for value range. */
+ double_int min;
+ /* Maximum for value range. */
+ double_int max;
+};
+
#define SSANAMES(fun) (fun)->gimple_df->ssa_names
#define MODIFIED_NORETURN_CALLS(fun) (fun)->gimple_df->modified_noreturn_calls
@@ -54,6 +63,15 @@ struct GTY(()) ptr_info_def
#define ssa_name(i) ((*cfun->gimple_df->ssa_names)[(i)])
+/* Type of value ranges. See value_range_d In tree-vrp.c for a
+ description of these types. */
+enum value_range_type { VR_UNDEFINED, VR_RANGE, VR_ANTI_RANGE, VR_VARYING };
+
+/* Sets the value range to SSA. */
+extern void set_range_info (tree ssa, double_int min, double_int max);
+/* Gets the value range from SSA. */
+extern enum value_range_type get_range_info (tree name, double_int *min,
+ double_int *max);
extern void init_ssanames (struct function *, int);
extern void fini_ssanames (void);
extern void ssanames_print_statistics (void);
@@ -71,6 +89,7 @@ extern struct ptr_info_def *get_ptr_info (tree);
extern tree copy_ssa_name_fn (struct function *, tree, gimple);
extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
extern tree duplicate_ssa_name_fn (struct function *, tree, gimple);
+extern void duplicate_ssa_name_range_info (tree, struct range_info_def *);
extern void release_defs (gimple);
extern void replace_ssa_name_symbol (tree, tree);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index ae27dc4..10e5844 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -41,9 +41,6 @@ along with GCC; see the file COPYING3. If not see
#include "optabs.h"
-/* Type of value ranges. See value_range_d for a description of these
- types. */
-enum value_range_type { VR_UNDEFINED, VR_RANGE, VR_ANTI_RANGE, VR_VARYING };
/* Range of values that can be associated with an SSA_NAME after VRP
has executed. */
@@ -9452,6 +9449,44 @@ vrp_finalize (void)
the datastructures built by VRP. */
identify_jump_threads ();
+ /* Set value range to non pointer SSA_NAMEs. */
+ for (i = 0; i < num_vr_values; i++)
+ if (vr_value[i])
+ {
+ tree name = ssa_name (i);
+
+ if (POINTER_TYPE_P (TREE_TYPE (name))
+ || (vr_value[i]->type == VR_VARYING)
+ || (vr_value[i]->type == VR_UNDEFINED))
+ continue;
+
+ if ((TREE_CODE (vr_value[i]->min) == INTEGER_CST)
+ && (TREE_CODE (vr_value[i]->max) == INTEGER_CST))
+ {
+ if (vr_value[i]->type == VR_RANGE)
+ set_range_info (name,
+ tree_to_double_int (vr_value[i]->min),
+ tree_to_double_int (vr_value[i]->max));
+ else if (vr_value[i]->type == VR_ANTI_RANGE)
+ {
+ /* VR_ANTI_RANGE ~[min, max] is encoded compactly as
+ [max + 1, min - 1] without additional attributes.
+ When min value > max value, we know that it is
+ VR_ANTI_RANGE; it is VR_RANGE othewise. */
+
+ /* Check for an empty range with minimum zero (of type
+ unsigned) that will wraparround. */
+ if (!(TYPE_UNSIGNED (TREE_TYPE (name))
+ && integer_zerop (vr_value[i]->min)))
+ set_range_info (name,
+ tree_to_double_int (vr_value[i]->max)
+ + double_int_one,
+ tree_to_double_int (vr_value[i]->min)
+ - double_int_one);
+ }
+ }
+ }
+
/* Free allocated memory. */
for (i = 0; i < num_vr_values; i++)
if (vr_value[i])
diff --git a/gcc/tree.h b/gcc/tree.h
index a263a2c..fb7c057 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1336,7 +1336,11 @@ extern void protected_set_expr_location (tree, location_t);
/* Attributes for SSA_NAMEs for pointer-type variables. */
#define SSA_NAME_PTR_INFO(N) \
- SSA_NAME_CHECK (N)->ssa_name.ptr_info
+ SSA_NAME_CHECK (N)->ssa_name.info.ptr_info
+
+/* Value range info Attributes for SSA_NAMEs of non pointer-type variables. */
+#define SSA_NAME_RANGE_INFO(N) \
+ SSA_NAME_CHECK (N)->ssa_name.info.range_info
/* Return the immediate_use information for an SSA_NAME. */
#define SSA_NAME_IMM_USE_NODE(NODE) SSA_NAME_CHECK (NODE)->ssa_name.imm_uses