public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 4/5] Sanitize irange::num_pairs
@ 2023-02-28 13:47 Richard Biener
  2023-03-01 10:38 ` Aldy Hernandez
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2023-02-28 13:47 UTC (permalink / raw)
  To: gcc-patches

irange::num_pairs has odd behavior for VR_ANTI_RANGE where it
claims there are two pairs when there's actually only one.  The
following is now able to get rid of this, also fixing
irange::legacy_upper_bound which special-cased ~[-INF, up]
to return +INF instead of properly doing that when up is not +INF.

	* value-range.h (irange::num_pairs): Always return
	m_num_ranges.
	* value-range.cc (irange::legacy_lower_bound): Remove
	pair == 1 case.
	(irange::legacy_upper_bound): Likewise.  Properly
	special-case ~[low, +INF].
---
 gcc/value-range.cc | 6 ++++--
 gcc/value-range.h  | 5 +----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index a535337c47a..143af5601c7 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -1208,7 +1208,8 @@ irange::legacy_lower_bound (unsigned pair) const
   if (m_kind == VR_ANTI_RANGE)
     {
       tree typ = type (), t;
-      if (pair == 1 || vrp_val_is_min (min ()))
+      gcc_checking_assert (pair == 0);
+      if (vrp_val_is_min (min ()))
 	t = wide_int_to_tree (typ, wi::to_wide (max ()) + 1);
       else
 	t = vrp_val_min (typ);
@@ -1235,7 +1236,8 @@ irange::legacy_upper_bound (unsigned pair) const
   if (m_kind == VR_ANTI_RANGE)
     {
       tree typ = type (), t;
-      if (pair == 1 || vrp_val_is_min (min ()))
+      gcc_checking_assert (pair == 0);
+      if (!vrp_val_is_max (max ()))
 	t = vrp_val_max (typ);
       else
 	t = wide_int_to_tree (typ, wi::to_wide (min ()) - 1);
diff --git a/gcc/value-range.h b/gcc/value-range.h
index f4ac73b499f..cfb51bad915 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -614,10 +614,7 @@ vrange::kind () const
 inline unsigned
 irange::num_pairs () const
 {
-  if (m_kind == VR_ANTI_RANGE)
-    return constant_p () ? 2 : 1;
-  else
-    return m_num_ranges;
+  return m_num_ranges;
 }
 
 inline tree
-- 
2.35.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-01 10:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-28 13:47 [PATCH 4/5] Sanitize irange::num_pairs Richard Biener
2023-03-01 10:38 ` Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).