https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100958
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is the start of the conversion to match.pd, there must be an easier way to
see the range too:
#if GIMPLE
/* Optimize
x in range [cst1, cst2] where cst2 = cst1 + 1
(x op CSTN) ? CST3 : CST4
# where op is == or != and N is 1 or 2
# where cst3 == cst4 + 1 or cst4 == cst3 + 1
to x + (min (cst3, cst4) - cst1) or
(min (cst3, cst4) + cst1) - x depending on op, N and which
of cst3 and cst4 is smaller. */
(for eqne (eq ne)
(simplify
(cond (eqne @0 INTEGER_CST@1) INTEGER_CST@2 INTEGER_CST@3)
(if (tree_int_cst_lt (@2, @3)
? wi::to_widest (@2) + 1 != wi::to_widest (@3)
: wi::to_widest (@3) + 1 != wi::to_widest (@2))
(with { wide_int min, max;
value_range r;
get_range_query (cfun)->range_of_expr (r, lhs);
if (r.kind () == VR_RANGE)
{
min = r.lower_bound ();
max = r.upper_bound ();
}
else
{
int prec = TYPE_PRECISION (TREE_TYPE (lhs));
signop sgn = TYPE_SIGN (TREE_TYPE (lhs));
min = wi::min_value (prec, sgn);
max = wi::max_value (prec, sgn);
}
}
(if (min + 1 == max
&& (wi::to_wide (@1) == min
|| wi::to_wide (@1) == max))
#endif