public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1679] Unify MINUS_EXPR range operator
@ 2023-06-10 0:34 Andrew Macleod
0 siblings, 0 replies; only message in thread
From: Andrew Macleod @ 2023-06-10 0:34 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d5818a361779e19b9c17295c6a014c4145c73937
commit r14-1679-gd5818a361779e19b9c17295c6a014c4145c73937
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Fri Jun 9 13:42:39 2023 -0400
Unify MINUS_EXPR range operator
Move the declaration of the class to the range-op-mixed header, add the
floating point prototypes as well, and use it in the new unified table.
* range-op-float.cc (foperator_minus): Remove. Move prototypes
to range-op-mixed.h
(operator_minus::fold_range): Rename from foperator_minus.
(operator_minus::op1_range): Ditto.
(operator_minus::op2_range): Ditto.
(operator_minus::rv_fold): Ditto.
(float_table::float_table): Remove MINUS_EXPR.
* range-op-mixed.h (class operator_minus): Combined from integer
and float files.
* range-op.cc (op_minus): New object.
(unified_table::unified_table): Add MINUS_EXPR.
(class operator_minus): Move to range-op-mixed.h.
(integral_table::integral_table): Remove MINUS_EXPR.
(pointer_table::pointer_table): Remove MINUS_EXPR.
Diff:
---
gcc/range-op-float.cc | 93 ++++++++++++++++++++++++---------------------------
gcc/range-op-mixed.h | 42 +++++++++++++++++++++++
gcc/range-op.cc | 39 ++++-----------------
3 files changed, 93 insertions(+), 81 deletions(-)
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 2b177c3d683..db76dd5f39e 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -2286,56 +2286,52 @@ operator_plus::rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub,
}
-class foperator_minus : public range_operator
+bool
+operator_minus::op1_range (frange &r, tree type,
+ const frange &lhs, const frange &op2,
+ relation_trio) const
{
- using range_operator::op1_range;
- using range_operator::op2_range;
-public:
- virtual bool op1_range (frange &r, tree type,
- const frange &lhs,
- const frange &op2,
- relation_trio = TRIO_VARYING) const final override
- {
- if (lhs.undefined_p ())
- return false;
- frange wlhs = float_widen_lhs_range (type, lhs);
- return float_binary_op_range_finish (
- range_op_handler (PLUS_EXPR).fold_range (r, type, wlhs, op2),
- r, type, wlhs);
- }
- virtual bool op2_range (frange &r, tree type,
- const frange &lhs,
- const frange &op1,
- relation_trio = TRIO_VARYING) const final override
- {
- if (lhs.undefined_p ())
- return false;
- frange wlhs = float_widen_lhs_range (type, lhs);
- return float_binary_op_range_finish (fold_range (r, type, op1, wlhs),
- r, type, wlhs);
- }
-private:
- void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
- tree type,
- const REAL_VALUE_TYPE &lh_lb,
- const REAL_VALUE_TYPE &lh_ub,
- const REAL_VALUE_TYPE &rh_lb,
- const REAL_VALUE_TYPE &rh_ub,
- relation_kind) const final override
- {
- frange_arithmetic (MINUS_EXPR, type, lb, lh_lb, rh_ub, dconstninf);
- frange_arithmetic (MINUS_EXPR, type, ub, lh_ub, rh_lb, dconstinf);
+ if (lhs.undefined_p ())
+ return false;
+ frange wlhs = float_widen_lhs_range (type, lhs);
+ return float_binary_op_range_finish (
+ range_op_handler (PLUS_EXPR).fold_range (r, type, wlhs, op2),
+ r, type, wlhs);
+}
- // [+INF] - [+INF] = NAN
- if (real_isinf (&lh_ub, false) && real_isinf (&rh_ub, false))
- maybe_nan = true;
- // [-INF] - [-INF] = NAN
- else if (real_isinf (&lh_lb, true) && real_isinf (&rh_lb, true))
- maybe_nan = true;
- else
- maybe_nan = false;
- }
-} fop_minus;
+bool
+operator_minus::op2_range (frange &r, tree type,
+ const frange &lhs, const frange &op1,
+ relation_trio) const
+{
+ if (lhs.undefined_p ())
+ return false;
+ frange wlhs = float_widen_lhs_range (type, lhs);
+ return float_binary_op_range_finish (fold_range (r, type, op1, wlhs),
+ r, type, wlhs);
+}
+
+void
+operator_minus::rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub,
+ bool &maybe_nan, tree type,
+ const REAL_VALUE_TYPE &lh_lb,
+ const REAL_VALUE_TYPE &lh_ub,
+ const REAL_VALUE_TYPE &rh_lb,
+ const REAL_VALUE_TYPE &rh_ub,
+ relation_kind) const
+{
+ frange_arithmetic (MINUS_EXPR, type, lb, lh_lb, rh_ub, dconstninf);
+ frange_arithmetic (MINUS_EXPR, type, ub, lh_ub, rh_lb, dconstinf);
+
+ // [+INF] - [+INF] = NAN
+ if (real_isinf (&lh_ub, false) && real_isinf (&rh_ub, false))
+ maybe_nan = true;
+ // [-INF] - [-INF] = NAN
+ else if (real_isinf (&lh_lb, true) && real_isinf (&rh_lb, true))
+ maybe_nan = true;
+ else
+ maybe_nan = false;
+}
class foperator_mult_div_base : public range_operator
@@ -2679,7 +2675,6 @@ private:
float_table::float_table ()
{
set (NEGATE_EXPR, fop_negate);
- set (MINUS_EXPR, fop_minus);
set (MULT_EXPR, fop_mult);
}
diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index a942808ff91..520ec1929b9 100644
--- a/gcc/range-op-mixed.h
+++ b/gcc/range-op-mixed.h
@@ -388,4 +388,46 @@ private:
const wide_int &rh_ub) const final override;
};
+
+class operator_minus : public range_operator
+{
+public:
+ using range_operator::fold_range;
+ using range_operator::op1_range;
+ using range_operator::op2_range;
+ using range_operator::lhs_op1_relation;
+ bool op1_range (irange &r, tree type,
+ const irange &lhs, const irange &op2,
+ relation_trio) const final override;
+ bool op1_range (frange &r, tree type,
+ const frange &lhs, const frange &op2,
+ relation_trio = TRIO_VARYING) const final override;
+
+ bool op2_range (irange &r, tree type,
+ const irange &lhs, const irange &op1,
+ relation_trio) const final override;
+ bool op2_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op1,
+ relation_trio = TRIO_VARYING) const final override;
+
+ relation_kind lhs_op1_relation (const irange &lhs,
+ const irange &op1, const irange &op2,
+ relation_kind rel) const final override;
+ bool op1_op2_relation_effect (irange &lhs_range, tree type,
+ const irange &op1_range,
+ const irange &op2_range,
+ relation_kind rel) 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,
+ const wide_int &rh_ub) const final override;
+ void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub,
+ bool &maybe_nan, tree type,
+ const REAL_VALUE_TYPE &lh_lb, const REAL_VALUE_TYPE &lh_ub,
+ const REAL_VALUE_TYPE &rh_lb, const REAL_VALUE_TYPE &rh_ub,
+ relation_kind) const final override;
+};
#endif // GCC_RANGE_OP_MIXED_H
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index b4cdaf5af8b..209447928d8 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -73,6 +73,7 @@ operator_cst op_cst;
operator_cast op_cast;
operator_plus op_plus;
operator_abs op_abs;
+operator_minus op_minus;
// Invoke the initialization routines for each class of range.
@@ -97,6 +98,7 @@ unified_table::unified_table ()
set (CONVERT_EXPR, op_cast);
set (PLUS_EXPR, op_plus);
set (ABS_EXPR, op_abs);
+ set (MINUS_EXPR, op_minus);
}
// The tables are hidden and accessed via a simple extern function.
@@ -1787,38 +1789,12 @@ operator_widen_plus_unsigned::wi_fold (irange &r, tree type,
r = int_range<2> (type, new_lb, new_ub);
}
-class operator_minus : public range_operator
+void
+operator_minus::update_bitmask (irange &r, const irange &lh,
+ const irange &rh) const
{
- using range_operator::fold_range;
- using range_operator::op1_range;
- using range_operator::op2_range;
- using range_operator::lhs_op1_relation;
-public:
- virtual bool op1_range (irange &r, tree type,
- const irange &lhs,
- const irange &op2,
- relation_trio) const;
- virtual bool op2_range (irange &r, tree type,
- const irange &lhs,
- const irange &op1,
- relation_trio) const;
- 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 relation_kind lhs_op1_relation (const irange &lhs,
- const irange &op1,
- const irange &op2,
- relation_kind rel) const;
- virtual bool op1_op2_relation_effect (irange &lhs_range,
- tree type,
- const irange &op1_range,
- const irange &op2_range,
- relation_kind rel) const;
- void update_bitmask (irange &r, const irange &lh, const irange &rh) const
- { update_known_bitmask (r, MINUS_EXPR, lh, rh); }
-} op_minus;
+ update_known_bitmask (r, MINUS_EXPR, lh, rh);
+}
void
operator_minus::wi_fold (irange &r, tree type,
@@ -4682,7 +4658,6 @@ pointer_or_operator::wi_fold (irange &r, tree type,
\f
integral_table::integral_table ()
{
- set (MINUS_EXPR, op_minus);
set (MIN_EXPR, op_min);
set (MAX_EXPR, op_max);
set (MULT_EXPR, op_mult);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-06-10 0:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-10 0:34 [gcc r14-1679] Unify MINUS_EXPR range operator Andrew Macleod
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).