This patch adjusts XORing of ranges where the operands are known to be
equal or not equal.

We should probably do the same thing for the op[12]_range methods.

Tested on x86-64 Linux.

gcc/ChangeLog:

        * range-op.cc (operator_bitwise_xor::op1_op2_relation_effect):
        New.
---
 gcc/range-op.cc | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 4bdd14dd6f7..b1fb25c77f8 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3101,6 +3101,11 @@ public:
                          const irange &lhs,
                          const irange &op1,
                          relation_kind rel = VREL_NONE) 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_bitwise_xor;
 
 void
@@ -3134,6 +3139,34 @@ operator_bitwise_xor::wi_fold (irange &r, tree type,
     r.set_varying (type);
 }
 
+bool
+operator_bitwise_xor::op1_op2_relation_effect (irange &lhs_range,
+                                              tree type,
+                                              const irange &,
+                                              const irange &,
+                                              relation_kind rel) const
+{
+  if (rel == VREL_NONE)
+    return false;
+
+  int_range<2> rel_range;
+
+  switch (rel)
+    {
+    case EQ_EXPR:
+      rel_range.set_zero (type);
+      break;
+    case NE_EXPR:
+      rel_range.set_nonzero (type);
+      break;
+    default:
+      return false;
+    }
+
+  lhs_range.intersect (rel_range);
+  return true;
+}
+
 bool
 operator_bitwise_xor::op1_range (irange &r, tree type,
                                 const irange &lhs,
-- 
2.31.1

Reply via email to