re PR middle-end/34070 (Wrong code for (int)x%4)
2007-11-12 Richard Guenther <rguenther@suse.de> PR middle-end/34070 * fold-const.c (fold_binary): If testing for non-negative operands with tree_expr_nonnegative_warnv_p make sure to use op0 which has all (sign) conversions retained. * gcc.c-torture/execute/pr34070-1.c: New testcase. * gcc.c-torture/execute/pr34070-2.c: Likewise. From-SVN: r130098
This commit is contained in:
parent
65648dd47e
commit
916c75b473
@ -1,3 +1,10 @@
|
||||
2007-11-12 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
PR middle-end/34070
|
||||
* fold-const.c (fold_binary): If testing for non-negative
|
||||
operands with tree_expr_nonnegative_warnv_p make sure to
|
||||
use op0 which has all (sign) conversions retained.
|
||||
|
||||
2007-11-12 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
PR middle-end/34027
|
||||
|
@ -11230,7 +11230,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
|
||||
strict_overflow_p = false;
|
||||
if (TREE_CODE (arg1) == LSHIFT_EXPR
|
||||
&& (TYPE_UNSIGNED (type)
|
||||
|| tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p)))
|
||||
|| tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p)))
|
||||
{
|
||||
tree sval = TREE_OPERAND (arg1, 0);
|
||||
if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0)
|
||||
@ -11356,7 +11356,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
|
||||
strict_overflow_p = false;
|
||||
if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR)
|
||||
&& (TYPE_UNSIGNED (type)
|
||||
|| tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p)))
|
||||
|| tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p)))
|
||||
{
|
||||
tree c = arg1;
|
||||
/* Also optimize A % (C << N) where C is a power of 2,
|
||||
|
@ -1,3 +1,9 @@
|
||||
2007-11-12 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
PR middle-end/34070
|
||||
* gcc.c-torture/execute/pr34070-1.c: New testcase.
|
||||
* gcc.c-torture/execute/pr34070-2.c: Likewise.
|
||||
|
||||
2007-11-12 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
PR middle-end/34027
|
||||
|
13
gcc/testsuite/gcc.c-torture/execute/pr34070-1.c
Normal file
13
gcc/testsuite/gcc.c-torture/execute/pr34070-1.c
Normal file
@ -0,0 +1,13 @@
|
||||
extern void abort (void);
|
||||
|
||||
int f(unsigned int x)
|
||||
{
|
||||
return ((int)x) % 4;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (f(-1) != -1)
|
||||
abort ();
|
||||
return 0;
|
||||
}
|
13
gcc/testsuite/gcc.c-torture/execute/pr34070-2.c
Normal file
13
gcc/testsuite/gcc.c-torture/execute/pr34070-2.c
Normal file
@ -0,0 +1,13 @@
|
||||
extern void abort (void);
|
||||
|
||||
int f(unsigned int x, int n)
|
||||
{
|
||||
return ((int)x) / (1 << n);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (f(-1, 1) != 0)
|
||||
abort ();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user