From: Richard Sandiford Date: Wed, 20 Dec 2017 12:56:05 +0000 (+0000) Subject: poly_int: pointer_may_wrap_p X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c036acdeecba22a4cb826a3dd21904154265a581;p=gcc.git 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 Alan Hayward David Sherwood 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 Co-Authored-By: David Sherwood From-SVN: r255890 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d3b8c8db09a..9a60b00e19b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-12-20 Richard Sandiford + Alan Hayward + David Sherwood + + * 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 Alan Hayward David Sherwood diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c9551d93d1e..75bc7627a07 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8325,48 +8325,50 @@ maybe_canonicalize_comparison (location_t loc, enum tree_code code, tree type, expressions like &p->x which can not wrap. */ 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))) return true; - if (bitpos < 0) + if (maybe_lt (bitpos, 0)) return true; - wide_int wi_offset; + poly_wide_int wi_offset; int precision = TYPE_PRECISION (TREE_TYPE (base)); if (offset == NULL_TREE) 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; else - wi_offset = wi::to_wide (offset); + wi_offset = wi::to_poly_wide (offset); bool overflow; - wide_int units = wi::shwi (bitpos / BITS_PER_UNIT, precision); - wide_int total = wi::add (wi_offset, units, UNSIGNED, &overflow); + poly_wide_int units = wi::shwi (bits_to_bytes_round_down (bitpos), + precision); + poly_wide_int total = wi::add (wi_offset, units, UNSIGNED, &overflow); if (overflow) 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; - HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (TREE_TYPE (base))); - if (size <= 0) - return true; + if (known_le (total_hwi, size)) + return false; /* We can do slightly better for SIZE if we have an ADDR_EXPR of an array. */ - if (TREE_CODE (base) == ADDR_EXPR) - { - HOST_WIDE_INT base_size; - - base_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (base, 0))); - if (base_size > 0 && size < base_size) - size = base_size; - } + if (TREE_CODE (base) == ADDR_EXPR + && poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (TREE_OPERAND (base, 0))), + &size) + && maybe_ne (size, 0U) + && known_le (total_hwi, size)) + return false; - return total.to_uhwi () > (unsigned HOST_WIDE_INT) size; + return true; } /* Return a positive integer when the symbol DECL is known to have