public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED 11/23] Implement operator_min and operator_max for prange.
Date: Sat,  4 May 2024 10:30:39 +0200	[thread overview]
Message-ID: <20240504083056.139719-12-aldyh@redhat.com> (raw)
In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com>

gcc/ChangeLog:

	* range-op-mixed.h: Add overloaded declarations for pointer variants.
	* range-op-ptr.cc (operator_min::fold_range): New.
	(operator_min::pointers_handled_p): New.
	(operator_max::fold_range): New.
	(operator_max::pointers_handled_p): New.
---
 gcc/range-op-mixed.h | 12 ++++++++
 gcc/range-op-ptr.cc  | 70 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index 11b1bf0bca4..b69e674a78b 100644
--- a/gcc/range-op-mixed.h
+++ b/gcc/range-op-mixed.h
@@ -761,12 +761,18 @@ protected:
 class operator_min : public range_operator
 {
 public:
+  using range_operator::fold_range;
   using range_operator::update_bitmask;
+  bool fold_range (prange &r, tree type,
+		   const prange &op1,
+		   const prange &op2,
+		   relation_trio) const final override;
   void update_bitmask (irange &r, const irange &lh,
 		       const irange &rh) const override;
   // Check compatibility of all operands.
   bool operand_check_p (tree t1, tree t2, tree t3) const final override
     { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
+  bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override;
 protected:
   void wi_fold (irange &r, tree type, const wide_int &lh_lb,
 		const wide_int &lh_ub, const wide_int &rh_lb,
@@ -776,12 +782,18 @@ protected:
 class operator_max : public range_operator
 {
 public:
+  using range_operator::fold_range;
   using range_operator::update_bitmask;
+  bool fold_range (prange &r, tree type,
+		   const prange &op1,
+		   const prange &op2,
+		   relation_trio) const final override;
   void update_bitmask (irange &r, const irange &lh,
       const irange &rh) const override;
   // Check compatibility of all operands.
   bool operand_check_p (tree t1, tree t2, tree t3) const final override
     { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
+  bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override;
 protected:
   void wi_fold (irange &r, tree type, const wide_int &lh_lb,
 		const wide_int &lh_ub, const wide_int &rh_lb,
diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc
index b8f86c8e838..0addd1096c2 100644
--- a/gcc/range-op-ptr.cc
+++ b/gcc/range-op-ptr.cc
@@ -951,6 +951,76 @@ operator_cast::pointers_handled_p (range_op_dispatch_type type,
     }
 }
 
+bool
+operator_min::fold_range (prange &r, tree type,
+			  const prange &op1,
+			  const prange &op2,
+			  relation_trio) const
+{
+  // For MIN/MAX expressions with pointers, we only care about
+  // nullness.  If both are non null, then the result is nonnull.
+  // If both are null, then the result is null.  Otherwise they
+  // are varying.
+  if (!range_includes_zero_p (op1)
+      && !range_includes_zero_p (op2))
+    r.set_nonzero (type);
+  else if (op1.zero_p () && op2.zero_p ())
+    r.set_zero (type);
+  else
+    r.set_varying (type);
+
+  update_known_bitmask (r, MIN_EXPR, op1, op2);
+  return true;
+}
+
+bool
+operator_min::pointers_handled_p (range_op_dispatch_type type,
+				  unsigned dispatch) const
+{
+  switch (type)
+    {
+    case DISPATCH_FOLD_RANGE:
+      return dispatch == RO_PPP;
+    default:
+      return true;
+    }
+}
+
+bool
+operator_max::fold_range (prange &r, tree type,
+			  const prange &op1,
+			  const prange &op2,
+			  relation_trio) const
+{
+  // For MIN/MAX expressions with pointers, we only care about
+  // nullness.  If both are non null, then the result is nonnull.
+  // If both are null, then the result is null.  Otherwise they
+  // are varying.
+  if (!range_includes_zero_p (op1)
+      && !range_includes_zero_p (op2))
+    r.set_nonzero (type);
+  else if (op1.zero_p () && op2.zero_p ())
+    r.set_zero (type);
+  else
+    r.set_varying (type);
+
+  update_known_bitmask (r, MAX_EXPR, op1, op2);
+  return true;
+}
+
+bool
+operator_max::pointers_handled_p (range_op_dispatch_type type,
+				  unsigned dispatch) const
+{
+  switch (type)
+    {
+    case DISPATCH_FOLD_RANGE:
+      return dispatch == RO_PPP;
+    default:
+      return true;
+    }
+}
+
 // Initialize any pointer operators to the primary table
 
 void
-- 
2.44.0


  parent reply	other threads:[~2024-05-04  8:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-04  8:30 [PATCH 00/23] prange: pointer ranges Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 01/23] Minimal prange class showing inlining degradation to VRP Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 02/23] Implement basic prange class Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 03/23] Add streaming support for prange Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 04/23] Add storage " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 05/23] Add hashing " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 06/23] Add prange implementation for get_legacy_range Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 07/23] Implement range-op dispatch for prange Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 08/23] Implement operator_identity " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 09/23] Implement operator_cst " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 10/23] Implement operator_cast " Aldy Hernandez
2024-05-04  8:30 ` Aldy Hernandez [this message]
2024-05-04  8:30 ` [COMMITTED 12/23] Implement operator_addr_expr " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 13/23] Implement pointer_plus_operator " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 14/23] Implement operator_pointer_diff " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 15/23] Implement operator_bitwise_and " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 16/23] Implement operator_bitwise_or " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 17/23] Implement operator_not_equal " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 18/23] Implement operator_equal " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 19/23] Implement operator_lt " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 20/23] Implement operator_le " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 21/23] Implement operator_gt " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 22/23] Implement operator_ge " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 23/23] Add prange entries in gimple-range-op.cc Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240504083056.139719-12-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).