re PR middle-end/45262 (Optimization results in wrong result on expression x>>31||(-x)>>31)
PR middle-end/45262 * fold-const.c (make_range) <case NEGATE_EXPR>: Punt if -a overflows. Normalize the range. * gcc.c-torture/execute/pr45262.c: New test. From-SVN: r163193
This commit is contained in:
parent
d2be807154
commit
a8c5681878
|
@ -3,6 +3,10 @@
|
|||
* builtins.c (fold_builtin_memory_op): Avoid -Wsign-compare
|
||||
warning.
|
||||
|
||||
PR middle-end/45262
|
||||
* fold-const.c (make_range) <case NEGATE_EXPR>: Punt if
|
||||
-a overflows. Normalize the range.
|
||||
|
||||
2010-08-12 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
PR tree-optimization/45232
|
||||
|
|
|
@ -3985,9 +3985,9 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
|
|||
n_high = range_binop (MINUS_EXPR, exp_type,
|
||||
build_int_cst (exp_type, 0),
|
||||
0, low, 0);
|
||||
low = n_low, high = n_high;
|
||||
exp = arg0;
|
||||
continue;
|
||||
if (n_high != 0 && TREE_OVERFLOW (n_high))
|
||||
break;
|
||||
goto normalize;
|
||||
|
||||
case BIT_NOT_EXPR:
|
||||
/* ~ X -> -X - 1 */
|
||||
|
@ -4021,6 +4021,7 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
|
|||
if (TYPE_OVERFLOW_UNDEFINED (arg0_type))
|
||||
*strict_overflow_p = true;
|
||||
|
||||
normalize:
|
||||
/* Check for an unsigned range which has wrapped around the maximum
|
||||
value thus making n_high < n_low, and normalize it. */
|
||||
if (n_low && n_high && tree_int_cst_lt (n_high, n_low))
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2010-08-12 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR middle-end/45262
|
||||
* gcc.c-torture/execute/pr45262.c: New test.
|
||||
|
||||
2010-08-12 Uros Bizjak <ubizjak@gmail.com>
|
||||
|
||||
* gcc.dg/profile-generate-3.c: Call dg-require-profiling with
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/* PR middle-end/45262 */
|
||||
|
||||
extern void abort (void);
|
||||
|
||||
int
|
||||
foo (unsigned int x)
|
||||
{
|
||||
return ((int) x < 0) || ((int) (-x) < 0);
|
||||
}
|
||||
|
||||
int
|
||||
bar (unsigned int x)
|
||||
{
|
||||
return x >> 31 || (-x) >> 31;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
if (foo (1) != 1)
|
||||
abort ();
|
||||
if (foo (0) != 0)
|
||||
abort ();
|
||||
if (foo (-1) != 1)
|
||||
abort ();
|
||||
if (bar (1) != 1)
|
||||
abort ();
|
||||
if (bar (0) != 0)
|
||||
abort ();
|
||||
if (bar (-1) != 1)
|
||||
abort ();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue