Commit c036acde by Richard Sandiford Committed by Richard Sandiford

poly_int: pointer_may_wrap_p

This patch changes the bitpos argument to pointer_may_wrap_p from
HOST_WIDE_INT to poly_int64.  A later patch makes the callers track
polynomial offsets.

2017-12-20  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* fold-const.c (pointer_may_wrap_p): Take the offset as a
	HOST_WIDE_INT rather than a poly_int64.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>

From-SVN: r255890
parent 4a022c70
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
Alan Hayward <alan.hayward@arm.com> Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com> David Sherwood <david.sherwood@arm.com>
* fold-const.c (pointer_may_wrap_p): Take the offset as a
HOST_WIDE_INT rather than a poly_int64.
2017-12-20 Richard Sandiford <richard.sandiford@linaro.org>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
* gimple-ssa-store-merging.c (symbolic_number::bytepos): Change from * gimple-ssa-store-merging.c (symbolic_number::bytepos): Change from
HOST_WIDE_INT to poly_int64_pod. HOST_WIDE_INT to poly_int64_pod.
(perform_symbolic_merge): Update accordingly. (perform_symbolic_merge): Update accordingly.
...@@ -8325,48 +8325,50 @@ maybe_canonicalize_comparison (location_t loc, enum tree_code code, tree type, ...@@ -8325,48 +8325,50 @@ maybe_canonicalize_comparison (location_t loc, enum tree_code code, tree type,
expressions like &p->x which can not wrap. */ expressions like &p->x which can not wrap. */
static bool static bool
pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos) pointer_may_wrap_p (tree base, tree offset, poly_int64 bitpos)
{ {
if (!POINTER_TYPE_P (TREE_TYPE (base))) if (!POINTER_TYPE_P (TREE_TYPE (base)))
return true; return true;
if (bitpos < 0) if (maybe_lt (bitpos, 0))
return true; return true;
wide_int wi_offset; poly_wide_int wi_offset;
int precision = TYPE_PRECISION (TREE_TYPE (base)); int precision = TYPE_PRECISION (TREE_TYPE (base));
if (offset == NULL_TREE) if (offset == NULL_TREE)
wi_offset = wi::zero (precision); wi_offset = wi::zero (precision);
else if (TREE_CODE (offset) != INTEGER_CST || TREE_OVERFLOW (offset)) else if (!poly_int_tree_p (offset) || TREE_OVERFLOW (offset))
return true; return true;
else else
wi_offset = wi::to_wide (offset); wi_offset = wi::to_poly_wide (offset);
bool overflow; bool overflow;
wide_int units = wi::shwi (bitpos / BITS_PER_UNIT, precision); poly_wide_int units = wi::shwi (bits_to_bytes_round_down (bitpos),
wide_int total = wi::add (wi_offset, units, UNSIGNED, &overflow); precision);
poly_wide_int total = wi::add (wi_offset, units, UNSIGNED, &overflow);
if (overflow) if (overflow)
return true; return true;
if (!wi::fits_uhwi_p (total)) poly_uint64 total_hwi, size;
if (!total.to_uhwi (&total_hwi)
|| !poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (base))),
&size)
|| known_eq (size, 0U))
return true; return true;
HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (TREE_TYPE (base))); if (known_le (total_hwi, size))
if (size <= 0) return false;
return true;
/* We can do slightly better for SIZE if we have an ADDR_EXPR of an /* We can do slightly better for SIZE if we have an ADDR_EXPR of an
array. */ array. */
if (TREE_CODE (base) == ADDR_EXPR) if (TREE_CODE (base) == ADDR_EXPR
{ && poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (TREE_OPERAND (base, 0))),
HOST_WIDE_INT base_size; &size)
&& maybe_ne (size, 0U)
base_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (base, 0))); && known_le (total_hwi, size))
if (base_size > 0 && size < base_size) return false;
size = base_size;
}
return total.to_uhwi () > (unsigned HOST_WIDE_INT) size; return true;
} }
/* Return a positive integer when the symbol DECL is known to have /* Return a positive integer when the symbol DECL is known to have
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment