public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] [range-ops] Handle bitmasks for unary operators.
@ 2023-07-26  8:42 Aldy Hernandez
  2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for BIT_NOT_EXPR Aldy Hernandez
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aldy Hernandez @ 2023-07-26  8:42 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

It looks like we missed out on bitmasks for unary operators because we
were using bit_value_binop exclusively.  This patch hands off to
bit_value_unop when appropriate, thus allowing us to handle ABS and
BIT_NOT_EXPR, and others.  Follow-up patches will add the tweaks for the
range-ops entries themselves.

gcc/ChangeLog:

	* range-op.cc (update_known_bitmask): Handle unary operators.
---
 gcc/range-op.cc | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 6b5d4f2accd..d959a3e93dc 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -385,15 +385,29 @@ update_known_bitmask (irange &r, tree_code code,
   irange_bitmask lh_bits = lh.get_bitmask ();
   irange_bitmask rh_bits = rh.get_bitmask ();
 
-  bit_value_binop (code, sign, prec, &widest_value, &widest_mask,
-		   TYPE_SIGN (lh.type ()),
-		   TYPE_PRECISION (lh.type ()),
-		   widest_int::from (lh_bits.value (), sign),
-		   widest_int::from (lh_bits.mask (), sign),
-		   TYPE_SIGN (rh.type ()),
-		   TYPE_PRECISION (rh.type ()),
-		   widest_int::from (rh_bits.value (), sign),
-		   widest_int::from (rh_bits.mask (), sign));
+  switch (get_gimple_rhs_class (code))
+    {
+    case GIMPLE_UNARY_RHS:
+      bit_value_unop (code, sign, prec, &widest_value, &widest_mask,
+		      TYPE_SIGN (lh.type ()),
+		      TYPE_PRECISION (lh.type ()),
+		      widest_int::from (lh_bits.value (), sign),
+		      widest_int::from (lh_bits.mask (), sign));
+      break;
+    case GIMPLE_BINARY_RHS:
+      bit_value_binop (code, sign, prec, &widest_value, &widest_mask,
+		       TYPE_SIGN (lh.type ()),
+		       TYPE_PRECISION (lh.type ()),
+		       widest_int::from (lh_bits.value (), sign),
+		       widest_int::from (lh_bits.mask (), sign),
+		       TYPE_SIGN (rh.type ()),
+		       TYPE_PRECISION (rh.type ()),
+		       widest_int::from (rh_bits.value (), sign),
+		       widest_int::from (rh_bits.mask (), sign));
+      break;
+    default:
+      gcc_unreachable ();
+    }
 
   wide_int mask = wide_int::from (widest_mask, prec, sign);
   wide_int value = wide_int::from (widest_value, prec, sign);
-- 
2.41.0


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

* [COMMITTED] [range-ops] Handle bitmasks for BIT_NOT_EXPR.
  2023-07-26  8:42 [COMMITTED] [range-ops] Handle bitmasks for unary operators Aldy Hernandez
@ 2023-07-26  8:42 ` Aldy Hernandez
  2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for ABS_EXPR Aldy Hernandez
  2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for ABSU_EXPR Aldy Hernandez
  2 siblings, 0 replies; 4+ messages in thread
From: Aldy Hernandez @ 2023-07-26  8:42 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* range-op-mixed.h (class operator_bitwise_not): Add update_bitmask.
	* range-op.cc (operator_bitwise_not::update_bitmask): New.
---
 gcc/range-op-mixed.h | 2 ++
 gcc/range-op.cc      | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index 6944742ecbc..ead41ed0515 100644
--- a/gcc/range-op-mixed.h
+++ b/gcc/range-op-mixed.h
@@ -551,6 +551,8 @@ public:
   bool op1_range (irange &r, tree type,
 		  const irange &lhs, const irange &op2,
 		  relation_trio rel = TRIO_VARYING) const final override;
+  void update_bitmask (irange &r, const irange &lh,
+		       const irange &rh) const final override;
 };
 
 class operator_bitwise_xor : public range_operator
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index d959a3e93dc..13ba973a08d 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -4027,6 +4027,13 @@ operator_bitwise_not::op1_range (irange &r, tree type,
   return fold_range (r, type, lhs, op2);
 }
 
+void
+operator_bitwise_not::update_bitmask (irange &r, const irange &lh,
+				      const irange &rh) const
+{
+  update_known_bitmask (r, BIT_NOT_EXPR, lh, rh);
+}
+
 
 bool
 operator_cst::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
-- 
2.41.0


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

* [COMMITTED] [range-ops] Handle bitmasks for ABS_EXPR.
  2023-07-26  8:42 [COMMITTED] [range-ops] Handle bitmasks for unary operators Aldy Hernandez
  2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for BIT_NOT_EXPR Aldy Hernandez
@ 2023-07-26  8:42 ` Aldy Hernandez
  2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for ABSU_EXPR Aldy Hernandez
  2 siblings, 0 replies; 4+ messages in thread
From: Aldy Hernandez @ 2023-07-26  8:42 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* range-op-mixed.h (class operator_abs): Add update_bitmask.
	* range-op.cc (operator_abs::update_bitmask): New.
---
 gcc/range-op-mixed.h | 2 ++
 gcc/range-op.cc      | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index ead41ed0515..70550c52232 100644
--- a/gcc/range-op-mixed.h
+++ b/gcc/range-op-mixed.h
@@ -408,6 +408,8 @@ class operator_abs : public range_operator
   bool op1_range (frange &r, tree type,
 		  const frange &lhs, const frange &op2,
 		  relation_trio rel = TRIO_VARYING) const final override;
+  void update_bitmask (irange &r, const irange &lh,
+		       const irange &rh) const final override;
 private:
   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.cc b/gcc/range-op.cc
index 13ba973a08d..bfab53caea0 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -4208,6 +4208,12 @@ operator_abs::op1_range (irange &r, tree type,
   return true;
 }
 
+void
+operator_abs::update_bitmask (irange &r, const irange &lh,
+			      const irange &rh) const
+{
+  update_known_bitmask (r, ABS_EXPR, lh, rh);
+}
 
 class operator_absu : public range_operator
 {
-- 
2.41.0


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

* [COMMITTED] [range-ops] Handle bitmasks for ABSU_EXPR.
  2023-07-26  8:42 [COMMITTED] [range-ops] Handle bitmasks for unary operators Aldy Hernandez
  2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for BIT_NOT_EXPR Aldy Hernandez
  2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for ABS_EXPR Aldy Hernandez
@ 2023-07-26  8:42 ` Aldy Hernandez
  2 siblings, 0 replies; 4+ messages in thread
From: Aldy Hernandez @ 2023-07-26  8:42 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* range-op.cc (class operator_absu): Add update_bitmask.
	(operator_absu::update_bitmask): New.
---
 gcc/range-op.cc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index bfab53caea0..5653ca0d186 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -4221,6 +4221,8 @@ class operator_absu : public range_operator
   virtual void wi_fold (irange &r, tree type,
 			const wide_int &lh_lb, const wide_int &lh_ub,
 			const wide_int &rh_lb, const wide_int &rh_ub) const;
+  virtual void update_bitmask (irange &r, const irange &lh,
+			       const irange &rh) const final override;
 } op_absu;
 
 void
@@ -4258,6 +4260,13 @@ operator_absu::wi_fold (irange &r, tree type,
   r = int_range<1> (type, new_lb, new_ub);
 }
 
+void
+operator_absu::update_bitmask (irange &r, const irange &lh,
+			      const irange &rh) const
+{
+  update_known_bitmask (r, ABSU_EXPR, lh, rh);
+}
+
 
 bool
 operator_negate::fold_range (irange &r, tree type,
-- 
2.41.0


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

end of thread, other threads:[~2023-07-26  8:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26  8:42 [COMMITTED] [range-ops] Handle bitmasks for unary operators Aldy Hernandez
2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for BIT_NOT_EXPR Aldy Hernandez
2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for ABS_EXPR Aldy Hernandez
2023-07-26  8:42 ` [COMMITTED] [range-ops] Handle bitmasks for ABSU_EXPR 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).