Commit 1651b094 by Jakub Jelinek Committed by Jakub Jelinek

re PR tree-optimization/89143 (comparison of abs(i) against excessive constant…

re PR tree-optimization/89143 (comparison of abs(i) against excessive constant less than UXXX_MAX no longer folded)

	PR tree-optimization/89143
	* wide-int-range.h (wide_int_range_absu): Declare.
	* wide-int-range.cc (wide_int_range_absu): New function.
	* tree-vrp.c (extract_range_from_unary_expr): Handle ABSU_EXPR.

	* gcc.dg/tree-ssa/vrp121.c: New test.

From-SVN: r268445
parent ac33bce8
2019-02-01 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/89143
* wide-int-range.h (wide_int_range_absu): Declare.
* wide-int-range.cc (wide_int_range_absu): New function.
* tree-vrp.c (extract_range_from_unary_expr): Handle ABSU_EXPR.
PR tree-optimization/88107
* tree-cfg.c (find_outermost_region_in_block): Add ALL argument,
instead of assertion that eh_region_outermost is non-NULL, if it
......
2019-02-01 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/89143
* gcc.dg/tree-ssa/vrp121.c: New test.
PR tree-optimization/88107
* gcc.dg/gomp/pr88107.c: New test.
......
/* PR tree-optimization/89143 */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump-not "link_error \\\(" "optimized" } } */
void link_error (void);
void
f1 (signed char i)
{
if (__builtin_abs (i) < 0 || __builtin_abs (i) > __SCHAR_MAX__ + 1)
link_error ();
}
void
f2 (signed char i)
{
if (i < 0 || i > 15)
__builtin_unreachable ();
if (__builtin_abs (i) < 0 || __builtin_abs (i) > 15)
link_error ();
}
void
f3 (signed char i)
{
if (i < 19 || i > 25)
__builtin_unreachable ();
if (__builtin_abs (i) < 19 || __builtin_abs (i) > 25)
link_error ();
}
void
f4 (signed char i)
{
if (i > -60)
__builtin_unreachable ();
if (__builtin_abs (i) < 60 || __builtin_abs (i) > __SCHAR_MAX__ + 1)
link_error ();
}
void
f5 (signed char i)
{
if (i < -__SCHAR_MAX__ || i > -30)
__builtin_unreachable ();
if (__builtin_abs (i) < 30 || __builtin_abs (i) > __SCHAR_MAX__)
link_error ();
}
void
f6 (signed char i)
{
if (i < -__SCHAR_MAX__ || i > 30)
__builtin_unreachable ();
if (__builtin_abs (i) < 0 || __builtin_abs (i) > __SCHAR_MAX__)
link_error ();
}
void
f7 (signed char i)
{
if (i < -31 || i > 30)
__builtin_unreachable ();
if (__builtin_abs (i) < 0 || __builtin_abs (i) > 31)
link_error ();
}
......@@ -2196,6 +2196,16 @@ extract_range_from_unary_expr (value_range_base *vr,
vr->set_varying ();
return;
}
else if (code == ABSU_EXPR)
{
wide_int wmin, wmax;
wide_int vr0_min, vr0_max;
extract_range_into_wide_ints (&vr0, SIGNED, prec, vr0_min, vr0_max);
wide_int_range_absu (wmin, wmax, prec, vr0_min, vr0_max);
vr->set (VR_RANGE, wide_int_to_tree (type, wmin),
wide_int_to_tree (type, wmax));
return;
}
/* For unhandled operations fall back to varying. */
vr->set_varying ();
......
......@@ -735,6 +735,37 @@ wide_int_range_abs (wide_int &min, wide_int &max,
return true;
}
/* Calculate ABSU_EXPR on a range and store the result in [MIN, MAX]. */
void
wide_int_range_absu (wide_int &min, wide_int &max,
unsigned prec, const wide_int &vr0_min,
const wide_int &vr0_max)
{
/* Pass through VR0 the easy cases. */
if (wi::ges_p (vr0_min, 0))
{
min = vr0_min;
max = vr0_max;
return;
}
min = wi::abs (vr0_min);
max = wi::abs (vr0_max);
/* If the range contains zero then we know that the minimum value in the
range will be zero. */
if (wi::ges_p (vr0_max, 0))
{
if (wi::gtu_p (min, max))
max = min;
min = wi::zero (prec);
}
else
/* Otherwise, swap MIN and MAX. */
std::swap (min, max);
}
/* Convert range in [VR0_MIN, VR0_MAX] with INNER_SIGN and INNER_PREC,
to a range in [MIN, MAX] with OUTER_SIGN and OUTER_PREC.
......
......@@ -107,6 +107,10 @@ extern bool wide_int_range_abs (wide_int &min, wide_int &max,
const wide_int &vr0_min,
const wide_int &vr0_max,
bool overflow_undefined);
extern void wide_int_range_absu (wide_int &min, wide_int &max,
unsigned prec,
const wide_int &vr0_min,
const wide_int &vr0_max);
extern bool wide_int_range_convert (wide_int &min, wide_int &max,
signop inner_sign,
unsigned inner_prec,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment