From 77f95085102ca89fe2755d5251617bf08771fc9d Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Tue, 2 Jun 2020 14:34:50 +0200 Subject: Rewrite operator_bitwise_and::remove_impossible_ranges using wide_ints. This fixes subtle incompatibilities between int, HOST_WIDE_INT, trees, and wide_ints that are causing endless grief. --- gcc/range-op.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'gcc') diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 434fc92..7090467 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1959,20 +1959,15 @@ unsigned_singleton_p (const irange &op) void operator_bitwise_and::remove_impossible_ranges (irange &r, - const irange &mask) const + const irange &rmask) const { - if (r.undefined_p () || !unsigned_singleton_p (mask)) + if (r.undefined_p () || !unsigned_singleton_p (rmask)) return; - tree tree_mask; - mask.singleton_p (&tree_mask); - if (!tree_fits_uhwi_p (tree_mask)) // FIXME: Rewrite with wide_int's. - return; - - unsigned HOST_WIDE_INT int_mask = tree_to_uhwi (tree_mask); + wide_int mask = rmask.lower_bound (); tree type = r.type (); int prec = TYPE_PRECISION (type); - int leading_zeros = wi::clz (mask.lower_bound ()); + int leading_zeros = wi::clz (mask); widest_irange impossible_ranges; /* We know that starting at the most significant bit, any 0 in the @@ -1986,8 +1981,9 @@ operator_bitwise_and::remove_impossible_ranges (irange &r, 0000 01xx [0000 0100, 0000 0111] 0000 0001 [0000 0001, 0000 0001] */ + wide_int one = wi::one (prec); for (int i = 0; i < prec - leading_zeros - 1; ++i) - if ((int_mask & ((unsigned HOST_WIDE_INT)1 << i)) == 0) + if (wi::bit_and (mask, wi::lshift (one, wi::uhwi (i, prec))) == 0) { tree lb = fold_build2 (LSHIFT_EXPR, type, build_one_cst (type), -- cgit v1.1