{
value_relation vrel;
value_relation *vrel_ptr = rel;
- // If the lhs doesn't tell us anything, neither will unwinding further.
- if (lhs.varying_p ())
- return false;
-
// Empty ranges are viral as they are on an unexecutable path.
if (lhs.undefined_p ())
{
if (!op1_in_chain && !op2_in_chain)
return false;
+ // If the lhs doesn't tell us anything and there are no relations, there
+ // is nothing to be learned.
+ if (lhs.varying_p () && !vrel_ptr)
+ return false;
+
bool res;
// Process logicals as they have special handling.
if (is_gimple_logical_p (stmt))
{
+ // If the lhs doesn't tell us anything, neither will combining operands.
+ if (lhs.varying_p ())
+ return false;
+
unsigned idx;
if ((idx = tracer.header ("compute_operand ")))
{
const wide_int &lh_ub,
const wide_int &rh_lb,
const wide_int &rh_ub) const;
+ virtual bool op2_range (irange &r, tree type,
+ const irange &lhs,
+ const irange &op1,
+ relation_trio = TRIO_VARYING) const;
} op_pointer_plus;
void
r.set_varying (type);
}
+bool
+pointer_plus_operator::op2_range (irange &r, tree type,
+ const irange &lhs ATTRIBUTE_UNUSED,
+ const irange &op1 ATTRIBUTE_UNUSED,
+ relation_trio trio) const
+{
+ relation_kind rel = trio.lhs_op1 ();
+ r.set_varying (type);
+
+ // If the LHS and OP1 are equal, the op2 must be zero.
+ if (rel == VREL_EQ)
+ r.set_zero (type);
+ // If the LHS and OP1 are not equal, the offset must be non-zero.
+ else if (rel == VREL_NE)
+ r.set_nonzero (type);
+ else
+ return false;
+ return true;
+}
class pointer_min_max_operator : public range_operator
{
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+void bar(char *);
+
+/* Ensure that PTR1 = PTR2 + OFF properly picks up the zero and non-zero
+ properties if PTR1 and PTR2 are known equal or non-equal. */
+
+void foo1 (char *p, char *pp, int off)
+{
+ char *q = p + off;
+ if (q != p)
+ {
+ if (off == 0)
+ bar (q);
+ }
+ else
+ {
+ if (off != 0)
+ bar (p);
+ }
+}
+
+void foo2 (char *p, char *pp, int off)
+{
+ char *q = p + off;
+ if (q == p)
+ {
+ if (off != 0)
+ bar (p);
+ }
+ else
+ {
+ if (off == 0)
+ bar (q);
+ }
+}
+
+/* { dg-final { scan-tree-dump-not "bar" "evrp" } } */