mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-24 23:56:05 +08:00
fold-const.c (size_binop): In the fast-paths for X+0...
* fold-const.c (size_binop): In the fast-paths for X+0, 0+X, X-0 and 1*X check that the constant hasn't overflowed, to preserve the TREE_OVERFLOW bit. (round_up): Provide an efficient implementation when rouding-up an INTEGER_CST to a power-of-two. * gcc-dg/large-size-array-3.c: New test case. From-SVN: r121252
This commit is contained in:
parent
5e851559ad
commit
74890d7bbd
@ -1,3 +1,11 @@
|
||||
2007-01-27 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* fold-const.c (size_binop): In the fast-paths for X+0, 0+X, X-0 and
|
||||
1*X check that the constant hasn't overflowed, to preserve the
|
||||
TREE_OVERFLOW bit.
|
||||
(round_up): Provide an efficient implementation when rouding-up an
|
||||
INTEGER_CST to a power-of-two.
|
||||
|
||||
2007-01-28 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
|
||||
|
||||
* doc/sourcebuild.texi: Add comma for clarity.
|
||||
|
@ -1815,13 +1815,23 @@ size_binop (enum tree_code code, tree arg0, tree arg1)
|
||||
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
|
||||
{
|
||||
/* And some specific cases even faster than that. */
|
||||
if (code == PLUS_EXPR && integer_zerop (arg0))
|
||||
return arg1;
|
||||
else if ((code == MINUS_EXPR || code == PLUS_EXPR)
|
||||
&& integer_zerop (arg1))
|
||||
return arg0;
|
||||
else if (code == MULT_EXPR && integer_onep (arg0))
|
||||
return arg1;
|
||||
if (code == PLUS_EXPR)
|
||||
{
|
||||
if (integer_zerop (arg0) && !TREE_OVERFLOW (arg0))
|
||||
return arg1;
|
||||
if (integer_zerop (arg1) && !TREE_OVERFLOW (arg1))
|
||||
return arg0;
|
||||
}
|
||||
else if (code == MINUS_EXPR)
|
||||
{
|
||||
if (integer_zerop (arg1) && !TREE_OVERFLOW (arg1))
|
||||
return arg0;
|
||||
}
|
||||
else if (code == MULT_EXPR)
|
||||
{
|
||||
if (integer_onep (arg0) && !TREE_OVERFLOW (arg0))
|
||||
return arg1;
|
||||
}
|
||||
|
||||
/* Handle general case of two integer constants. */
|
||||
return int_const_binop (code, arg0, arg1, 0);
|
||||
@ -13505,10 +13515,36 @@ round_up (tree value, int divisor)
|
||||
{
|
||||
tree t;
|
||||
|
||||
t = build_int_cst (TREE_TYPE (value), divisor - 1);
|
||||
value = size_binop (PLUS_EXPR, value, t);
|
||||
t = build_int_cst (TREE_TYPE (value), -divisor);
|
||||
value = size_binop (BIT_AND_EXPR, value, t);
|
||||
if (TREE_CODE (value) == INTEGER_CST)
|
||||
{
|
||||
unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (value);
|
||||
HOST_WIDE_INT high;
|
||||
|
||||
if ((low & (divisor - 1)) == 0)
|
||||
return value;
|
||||
|
||||
high = TREE_INT_CST_HIGH (value);
|
||||
low &= ~(divisor - 1);
|
||||
low += divisor;
|
||||
if (low == 0)
|
||||
high++;
|
||||
|
||||
t = build_int_cst_wide_type (TREE_TYPE (value), low, high);
|
||||
if ((TREE_OVERFLOW (value) || integer_zerop (t))
|
||||
&& !TREE_OVERFLOW (t))
|
||||
{
|
||||
t = copy_node (t);
|
||||
TREE_OVERFLOW (t) = 1;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = build_int_cst (TREE_TYPE (value), divisor - 1);
|
||||
value = size_binop (PLUS_EXPR, value, t);
|
||||
t = build_int_cst (TREE_TYPE (value), -divisor);
|
||||
value = size_binop (BIT_AND_EXPR, value, t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,3 +1,7 @@
|
||||
2007-01-27 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* gcc-dg/large-size-array-3.c: New test case.
|
||||
|
||||
2007-01-27 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* gfortran.dg/forall_7.f90: New test case.
|
||||
|
20
gcc/testsuite/gcc.dg/large-size-array-3.c
Normal file
20
gcc/testsuite/gcc.dg/large-size-array-3.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* { dg-do compile } */
|
||||
|
||||
#ifdef __LP64__
|
||||
#define DIM UINT_MAX>>1
|
||||
#else
|
||||
#define DIM 65536
|
||||
#endif
|
||||
|
||||
int
|
||||
sub (int *a)
|
||||
{
|
||||
return a[0];
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int a[DIM][DIM]; /* { dg-error "size of array 'a' is too large" } */
|
||||
return sub (&a[0][0]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user