diff options
author | Richard Sandiford <richard.sandiford@linaro.org> | 2017-12-20 12:56:05 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2017-12-20 12:56:05 +0000 |
commit | c036acdeecba22a4cb826a3dd21904154265a581 (patch) | |
tree | 6c6f29b5b1b11d72e87525a16d917bc1d45fdc43 /gcc | |
parent | 4a022c701b1dca1bfc3d73dc82dd5858525876ef (diff) | |
download | gcc-c036acdeecba22a4cb826a3dd21904154265a581.zip gcc-c036acdeecba22a4cb826a3dd21904154265a581.tar.gz gcc-c036acdeecba22a4cb826a3dd21904154265a581.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 42 |
2 files changed, 29 insertions, 20 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d3b8c8d..9a60b00 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -2,6 +2,13 @@ Alan Hayward <alan.hayward@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 HOST_WIDE_INT to poly_int64_pod. (perform_symbolic_merge): Update accordingly. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c9551d9..75bc762 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 |