+2019-11-05 Aldy Hernandez <aldyh@redhat.com>
+
+ * range-op.cc (wi_set_zero_nonzero_bits): Remove static qualifier.
+ * range-op.h (wi_set_zero_nonzero_bits): New prototype.
+ * tree-vrp.h (vrp_set_zero_nonzero_bits): Remove.
+ * tree-vrp.c (wide_int_range_set_zero_nonzero_bits): Remove.
+ (vrp_set_zero_nonzero_bits): Move to...
+ * vr-values.c (vr_set_zero_nonzero_bits): ...here.
+ (vr_values::simplify_bit_ops_using_ranges): Rename
+ vrp_set_zero_nonzero_bits to vr_set_zero_nonzero_bits.
+
2019-11-05 Martin Liska <mliska@suse.cz>
PR c++/92339
// for all numbers in the range the bit is 1, otherwise it might be 0
// or 1.
-static void
+void
wi_set_zero_nonzero_bits (tree type,
const wide_int &lb, const wide_int &ub,
wide_int &maybe_nonzero,
};
extern range_operator *range_op_handler (enum tree_code code, tree type);
-
extern void range_cast (value_range_base &, tree type);
+extern void wi_set_zero_nonzero_bits (tree type,
+ const wide_int &, const wide_int &,
+ wide_int &maybe_nonzero,
+ wide_int &mustbe_nonzero);
#endif // GCC_RANGE_OP_H
return !!cmp2;
}
-/* For range [LB, UB] compute two wide_int bit masks.
-
- In the MAY_BE_NONZERO bit mask, if some bit is unset, it means that
- for all numbers in the range the bit is 0, otherwise it might be 0
- or 1.
-
- In the MUST_BE_NONZERO bit mask, if some bit is set, it means that
- for all numbers in the range the bit is 1, otherwise it might be 0
- or 1. */
-
-static inline void
-wide_int_range_set_zero_nonzero_bits (signop sign,
- const wide_int &lb, const wide_int &ub,
- wide_int &may_be_nonzero,
- wide_int &must_be_nonzero)
-{
- may_be_nonzero = wi::minus_one (lb.get_precision ());
- must_be_nonzero = wi::zero (lb.get_precision ());
-
- if (wi::eq_p (lb, ub))
- {
- may_be_nonzero = lb;
- must_be_nonzero = may_be_nonzero;
- }
- else if (wi::ge_p (lb, 0, sign) || wi::lt_p (ub, 0, sign))
- {
- wide_int xor_mask = lb ^ ub;
- may_be_nonzero = lb | ub;
- must_be_nonzero = lb & ub;
- if (xor_mask != 0)
- {
- wide_int mask = wi::mask (wi::floor_log2 (xor_mask), false,
- may_be_nonzero.get_precision ());
- may_be_nonzero = may_be_nonzero | mask;
- must_be_nonzero = wi::bit_and_not (must_be_nonzero, mask);
- }
- }
-}
-
-/* value_range wrapper for wide_int_range_set_zero_nonzero_bits above.
-
- Return TRUE if VR was a constant range and we were able to compute
- the bit masks. */
-
-bool
-vrp_set_zero_nonzero_bits (const tree expr_type,
- const value_range_base *vr,
- wide_int *may_be_nonzero,
- wide_int *must_be_nonzero)
-{
- if (!range_int_cst_p (vr))
- {
- *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type));
- *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type));
- return false;
- }
- wide_int_range_set_zero_nonzero_bits (TYPE_SIGN (expr_type),
- wi::to_wide (vr->min ()),
- wi::to_wide (vr->max ()),
- *may_be_nonzero, *must_be_nonzero);
- return true;
-}
-
/* Create two value-ranges in *VR0 and *VR1 from the anti-range *AR
so that *VR0 U *VR1 == *AR. Returns true if that is possible,
false otherwise. If *AR can be represented with a single range
extern bool vrp_operand_equal_p (const_tree, const_tree);
extern enum value_range_kind intersect_range_with_nonzero_bits
(enum value_range_kind, wide_int *, wide_int *, const wide_int &, signop);
-extern bool vrp_set_zero_nonzero_bits (const tree, const value_range_base *,
- wide_int *, wide_int *);
extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
return false;
}
+/* value_range wrapper for wi_set_zero_nonzero_bits.
+
+ Return TRUE if VR was a constant range and we were able to compute
+ the bit masks. */
+
+static bool
+vr_set_zero_nonzero_bits (const tree expr_type,
+ const value_range_base *vr,
+ wide_int *may_be_nonzero,
+ wide_int *must_be_nonzero)
+{
+ if (range_int_cst_p (vr))
+ {
+ wi_set_zero_nonzero_bits (expr_type,
+ wi::to_wide (vr->min ()),
+ wi::to_wide (vr->max ()),
+ *may_be_nonzero, *must_be_nonzero);
+ return true;
+ }
+ *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type));
+ *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type));
+ return false;
+}
+
/* Optimize away redundant BIT_AND_EXPR and BIT_IOR_EXPR.
If all the bits that are being cleared by & are already
known to be zero from VR, or all the bits that are being
else
return false;
- if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0,
- &must_be_nonzero0))
+ if (!vr_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0,
+ &must_be_nonzero0))
return false;
- if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1,
- &must_be_nonzero1))
+ if (!vr_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1,
+ &must_be_nonzero1))
return false;
switch (gimple_assign_rhs_code (stmt))