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.
(cherry picked from commit
8d5f050dabbf6dd3b992c3b46661848dbcf30d9e)
--- /dev/null
+// { 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 ();
+}
signop sign = TYPE_SIGN (ttype);
wide_int type_min = wi::min_value (prec, sign);
wide_int type_max = wi::max_value (prec, sign);
- if (m_num_ranges == m_max_ranges
- && lower_bound () != type_min
- && upper_bound () != type_max)
- {
- m_base[1] = wide_int_to_tree (ttype, type_max);
- m_num_ranges = 1;
- return;
- }
// The algorithm is as follows. To calculate INVERT ([a,b][c,d]), we
// generate [-MIN, a-1][b+1, c-1][d+1, MAX].
//