aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2024-03-20 08:44:49 +0100
committerAldy Hernandez <aldyh@redhat.com>2024-05-04 10:25:51 +0200
commit1a4f5d499109d3f2a06bfd1403b6d47d6f55e481 (patch)
tree1c48de1cc80f262cf79d8e5c89f0696f7a3e64c1
parent95fce0dc73002d5c9557fa7260c7ba1e761136ff (diff)
downloadgcc-1a4f5d499109d3f2a06bfd1403b6d47d6f55e481.zip
gcc-1a4f5d499109d3f2a06bfd1403b6d47d6f55e481.tar.gz
gcc-1a4f5d499109d3f2a06bfd1403b6d47d6f55e481.tar.bz2
Implement operator_min and operator_max for prange.
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.
-rw-r--r--gcc/range-op-mixed.h12
-rw-r--r--gcc/range-op-ptr.cc70
2 files changed, 82 insertions, 0 deletions
diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index 11b1bf0..b69e674 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 b8f86c8..0addd10 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