re PR middle-end/11968 (Array reference is incorrectly computed for POINTERS_EXTEND_U...
authorRoger Sayle <roger@eyesopen.com>
Sat, 1 Nov 2003 00:59:53 +0000 (00:59 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Sat, 1 Nov 2003 00:59:53 +0000 (00:59 +0000)
PR middle-end/11968
* expr.c (expand_expr <MULT_EXPR>): Remove inappropriate and
confusing comment; distributivity isn't handled in expand_expr.
* fold-const.c (extract_muldiv_1 <PLUS_EXPR>):  Allow overflow
in distributivity, if wrap-around semantics are specified with
-fwrapv.

From-SVN: r73166

gcc/ChangeLog
gcc/expr.c
gcc/fold-const.c

index a4ca9c79e7dffd27842b7cb0b28f686bd6ce7370..7a217083737eeecaa7a7cd01422cea7d9c97dbe4 100644 (file)
@@ -1,3 +1,12 @@
+2003-10-31  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/11968
+       * expr.c (expand_expr <MULT_EXPR>): Remove inappropriate and
+       confusing comment; distributivity isn't handled in expand_expr.
+       * fold-const.c (extract_muldiv_1 <PLUS_EXPR>):  Allow overflow
+       in distributivity, if wrap-around semantics are specified with
+       -fwrapv.
+
 2003-11-01  Alan Modra  <amodra@bigpond.net.au>
 
        PR 12315
index cd37495badd66a95405f0aa52296805af3d181f7..347edb31bd2306725e9811cd02498b64fb17b519 100644 (file)
@@ -7854,16 +7854,6 @@ expand_expr (tree exp, rtx target, enum machine_mode tmode,
          op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
                             EXPAND_SUM);
 
-         /* If we knew for certain that this is arithmetic for an array
-            reference, and we knew the bounds of the array, then we could
-            apply the distributive law across (PLUS X C) for constant C.
-            Without such knowledge, we risk overflowing the computation
-            when both X and C are large, but X+C isn't.  */
-         /* ??? Could perhaps special-case EXP being unsigned and C being
-            positive.  In that case we are certain that X+C is no smaller
-            than X and so the transformed expression will overflow iff the
-            original would have.  */
-
          if (GET_CODE (op0) != REG)
            op0 = force_operand (op0, NULL_RTX);
          if (GET_CODE (op0) != REG)
index 85909a3f909aa09b00a8db0078a1fed3ad373eb0..3787915021e3c99b25c73fcdc347b1695175060f 100644 (file)
@@ -4433,8 +4433,11 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type)
       if (code == MULT_EXPR
          || integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0)))
        {
-         op1 = const_binop (code, convert (ctype, op1), convert (ctype, c), 0);
-         if (op1 == 0 || TREE_OVERFLOW (op1))
+         op1 = const_binop (code, convert (ctype, op1),
+                            convert (ctype, c), 0);
+         /* We allow the constant to overflow with wrapping semantics.  */
+         if (op1 == 0
+             || (TREE_OVERFLOW (op1) && ! flag_wrapv))
            break;
        }
       else