public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aldyh/heads/ranger-relational)] Andrew: Implement operator_minus::op1_op2_relation_effect.
@ 2021-04-21 15:02 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-04-21 15:02 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d9b9b6e6d6991884fc53c5fef63b8cbc9d630ae1

commit d9b9b6e6d6991884fc53c5fef63b8cbc9d630ae1
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Apr 20 16:15:41 2021 +0200

    Andrew: Implement operator_minus::op1_op2_relation_effect.

Diff:
---
 gcc/range-op.cc | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 62c031e9049..15be669f228 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -1212,6 +1212,11 @@ public:
 		        const wide_int &lh_ub,
 		        const wide_int &rh_lb,
 		        const wide_int &rh_ub) const;
+  virtual bool op1_op2_relation_effect (irange &lhs_range,
+					tree type,
+					const irange &op1_range,
+					const irange &op2_range,
+					relation_kind rel) const;
 } op_minus;
 
 void 
@@ -1226,6 +1231,42 @@ operator_minus::wi_fold (irange &r, tree type,
   value_range_with_overflow (r, type, new_lb, new_ub, ov_lb, ov_ub);
 }
 
+bool
+operator_minus::op1_op2_relation_effect (irange &lhs_range, tree type,
+				      const irange &op1_range ATTRIBUTE_UNUSED,
+				      const irange &op2_range ATTRIBUTE_UNUSED,
+				      relation_kind rel) const
+{
+  if (rel == VREL_NONE)
+    return false;
+
+  int_range<2> rel_range;
+  unsigned prec = TYPE_PRECISION (type);
+  signop sgn = TYPE_SIGN (type);
+
+  switch (rel)
+    {
+      // op1 > op2,  op1 - op2 can be restricted to  [1, max]
+      case GT_EXPR:
+	rel_range = int_range<2> (type, wi::one (prec),
+				  wi::max_value (prec, sgn));
+	break;
+      // op1 >= op2,  op1 - op2 can be restricted to  [0, max]
+      case GE_EXPR:
+	rel_range = int_range<2> (type, wi::zero (prec),
+				  wi::max_value (prec, sgn));
+	break;
+      // op1 == op2,  op1 - op2 can be restricted to  [0, 0]
+      case EQ_EXPR:
+	rel_range = int_range<2> (type, wi::zero (prec), wi::zero (prec));
+	break;
+      default:
+	return false;
+    }
+  lhs_range.intersect (rel_range);
+  return true;
+}
+
 bool
 operator_minus::op1_range (irange &r, tree type,
 			   const irange &lhs,


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-21 15:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 15:02 [gcc(refs/users/aldyh/heads/ranger-relational)] Andrew: Implement operator_minus::op1_op2_relation_effect 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).