Implement operator_bitwise_xor::op1_op2_relation_effect.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 26 Jul 2021 11:08:24 +0000 (06:08 -0500)
committerAldy Hernandez <aldyh@redhat.com>
Mon, 26 Jul 2021 14:49:14 +0000 (16:49 +0200)
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.

gcc/ChangeLog:

* range-op.cc (operator_bitwise_xor::op1_op2_relation_effect):
New.

gcc/range-op.cc

index 4bdd14d..b1fb25c 100644 (file)
@@ -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
@@ -3135,6 +3140,34 @@ operator_bitwise_xor::wi_fold (irange &r, tree 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,
                                 const irange &op2,