[PR102563] Do not clobber range in operator_lshift::op1_range.

We're clobbering the final range before we're done calculating it.

Tested on x86-64 Linux.

gcc/ChangeLog:

	PR tree-optimization/102563
	* range-op.cc (operator_lshift::op1_range): Do not clobber
	range.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr102563.c: New test.
This commit is contained in:
Aldy Hernandez 2021-10-02 16:59:26 +02:00
parent d7705b0ada
commit 6c0dd02964
2 changed files with 22 additions and 6 deletions

View file

@ -2112,8 +2112,6 @@ operator_lshift::op1_range (irange &r,
else
op_rshift.fold_range (tmp_range, utype, lhs, op2);
r.intersect (tmp_range);
// Start with ranges which can produce the LHS by right shifting the
// result by the shift amount.
// ie [0x08, 0xF0] = op1 << 2 will start with
@ -2128,13 +2126,15 @@ operator_lshift::op1_range (irange &r,
unsigned low_bits = TYPE_PRECISION (utype)
- TREE_INT_CST_LOW (shift_amount);
wide_int up_mask = wi::mask (low_bits, true, TYPE_PRECISION (utype));
wide_int new_ub = wi::bit_or (up_mask, r.upper_bound ());
wide_int new_lb = wi::set_bit (r.lower_bound (), low_bits);
wide_int new_ub = wi::bit_or (up_mask, tmp_range.upper_bound ());
wide_int new_lb = wi::set_bit (tmp_range.lower_bound (), low_bits);
int_range<2> fill_range (utype, new_lb, new_ub);
r.union_ (fill_range);
tmp_range.union_ (fill_range);
if (utype != type)
range_cast (r, type);
range_cast (tmp_range, type);
r.intersect (tmp_range);
return true;
}

View file

@ -0,0 +1,16 @@
// { dg-do compile }
// { dg-options "-O2 -w" }
int _bdf_parse_glyphs_bp;
long _bdf_parse_glyphs_nibbles;
void _bdf_parse_glyphs_p()
{
long p_2;
_bdf_parse_glyphs_nibbles = p_2 << 1;
for (; 0 < _bdf_parse_glyphs_nibbles;)
if (1 < _bdf_parse_glyphs_nibbles)
_bdf_parse_glyphs_bp = _bdf_parse_glyphs_p;
}