Remove buggy special case in irange::invert [PR109934].

This patch removes a buggy special case in irange::invert which seems
to have been broken for a while, and probably never triggered because
the legacy code was handled elsewhere, and the non-legacy code was
using an int_range_max of int_range<255> which made it extremely
likely for num_ranges == 255.  However, with auto-resizing ranges,
int_range_max will start off at 3 and can hit this bogus code in the
unswitching code.

	PR tree-optimization/109934

gcc/ChangeLog:

	* value-range.cc (irange::invert): Remove buggy special case.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr109934.c: New test.
This commit is contained in:
Aldy Hernandez 2023-05-23 12:34:45 +02:00
parent 0b4ae6e1ec
commit 8d5f050dab
2 changed files with 22 additions and 8 deletions

View File

@ -0,0 +1,22 @@
// { dg-do run }
// { dg-options "-O3" }
int printf(const char *, ...);
short a;
long b = 3, c;
int d(int e) {
switch (e)
case 111:
case 222:
case 44:
return 0;
return e;
}
int main() {
for (; a >= 0; --a)
if (d(c + 23) - 23)
b = 0;
if (b != 3)
__builtin_abort ();
}

View File

@ -1650,14 +1650,6 @@ irange::invert ()
wide_int type_min = wi::min_value (prec, sign);
wide_int type_max = wi::max_value (prec, sign);
m_nonzero_mask = wi::minus_one (prec);
if (m_num_ranges == m_max_ranges
&& lower_bound () != type_min
&& upper_bound () != type_max)
{
m_base[1] = type_max;
m_num_ranges = 1;
return;
}
// At this point, we need one extra sub-range to represent the
// inverse.