diff options
author | Roger Sayle <roger@eyesopen.com> | 2007-01-28 03:48:41 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2007-01-28 03:48:41 +0000 |
commit | 74890d7bbdacf14edfcd1e50bac0e5053a2bdf53 (patch) | |
tree | 79ff0e900f4c8f77577ddfd6116f7f43015bdc5c /gcc/fold-const.c | |
parent | 5e851559ad1c6b61d9b13b62a6f5bb536c5fbca1 (diff) | |
download | gcc-74890d7bbdacf14edfcd1e50bac0e5053a2bdf53.zip gcc-74890d7bbdacf14edfcd1e50bac0e5053a2bdf53.tar.gz gcc-74890d7bbdacf14edfcd1e50bac0e5053a2bdf53.tar.bz2 |
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
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index cd4d684..b606587 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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 { |