aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2024-05-09 23:37:30 +0200
committerAldy Hernandez <aldyh@redhat.com>2024-05-10 09:00:56 +0200
commitac255c7afeb8a558bd6224ff77277eebcd849d6e (patch)
treed5027afb15ebd39adce01ce90586f08b34f7f9d2 /gcc
parentd83070aebdb810e38f12d008e7a10acf1063f456 (diff)
downloadgcc-ac255c7afeb8a558bd6224ff77277eebcd849d6e.zip
gcc-ac255c7afeb8a558bd6224ff77277eebcd849d6e.tar.gz
gcc-ac255c7afeb8a558bd6224ff77277eebcd849d6e.tar.bz2
[prange] Do not assume all pointers are the same size [PR115009]
In a world with same sized pointers we can always reuse the storage slots, but since this is not always the case, we need to be more careful. However, we can always store an undefined, because that requires no extra storage. gcc/ChangeLog: PR tree-optimization/115009 * value-range-storage.cc (prange_storage::alloc): Do not assume all pointers are the same size. (prange_storage::prange_storage): Same. (prange_storage::fits_p): Same.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/value-range-storage.cc30
1 files changed, 19 insertions, 11 deletions
diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index bbae0da4..8e8d61d 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -593,12 +593,12 @@ frange_storage::fits_p (const frange &) const
prange_storage *
prange_storage::alloc (vrange_internal_alloc &allocator, const prange &r)
{
- // Assume all pointers are the same size.
- unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node));
- gcc_checking_assert (r.undefined_p () || TYPE_PRECISION (r.type ()) == prec);
-
- typedef trailing_wide_ints<NINTS> twi;
- size_t size = sizeof (prange_storage) + twi::extra_size (prec);
+ size_t size = sizeof (prange_storage);
+ if (!r.undefined_p ())
+ {
+ unsigned prec = TYPE_PRECISION (r.type ());
+ size += trailing_wide_ints<NINTS>::extra_size (prec);
+ }
prange_storage *p = static_cast <prange_storage *> (allocator.alloc (size));
new (p) prange_storage (r);
return p;
@@ -610,8 +610,12 @@ prange_storage::prange_storage (const prange &r)
{
// It is the caller's responsibility to allocate enough space such
// that the precision fits.
- unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node));
- m_trailing_ints.set_precision (prec);
+ if (r.undefined_p ())
+ // Undefined ranges do not require any extra space for trailing
+ // wide ints.
+ m_trailing_ints.set_precision (0);
+ else
+ m_trailing_ints.set_precision (TYPE_PRECISION (r.type ()));
set_prange (r);
}
@@ -669,10 +673,14 @@ prange_storage::equal_p (const prange &r) const
}
bool
-prange_storage::fits_p (const prange &) const
+prange_storage::fits_p (const prange &r) const
{
- // All pointers are the same size.
- return true;
+ // Undefined ranges always fit, because they don't store anything in
+ // the trailing wide ints.
+ if (r.undefined_p ())
+ return true;
+
+ return TYPE_PRECISION (r.type ()) <= m_trailing_ints.get_precision ();
}