[multiple changes]
authorRichard Guenther <rguenther@suse.de>
Mon, 23 Oct 2006 07:19:34 +0000 (07:19 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 23 Oct 2006 07:19:34 +0000 (07:19 +0000)
2006-10-24  Richard Guenther  <rguenther@suse.de>

PR middle-end/27132
PR middle-end/23295
* builtins.c (fold_binary): Remove checks for flag_wrapv
and flag_trapv where negate_expr_p covers these cases.

* gcc.dg/pr27132.c: New testcase.
* gcc.dg/pr23295.c: Likewise.
* gcc.dg/tree-ssa/pr23294.c: Adjust patterns.
* g++.dg/tree-ssa/pr19807.C: Likewise.

2006-10-23  Richard Guenther  <rguenther@suse.de>

PR middle-end/29548
* fold-const.c (fold_plusminus_mult_expr): Check exact power
of two on the absolute value.
(fold_binary): Fold x * -C to -x * C if x is easily negatable
and negating -C does not overflow.

From-SVN: r117969

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/pr19807.C
gcc/testsuite/gcc.dg/pr23295.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr27132.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr23294.c

index 655596dcc55c69e291f2b55a8baeaf7cbceb6f91..568ba2e78f5657e41ab8ac13cc84de5b62bb4369 100644 (file)
@@ -1,3 +1,18 @@
+2006-10-23  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/27132
+       PR middle-end/23295
+       * builtins.c (fold_binary): Remove checks for flag_wrapv
+       and flag_trapv where negate_expr_p covers these cases.
+
+2006-10-23  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/29548
+       * fold-const.c (fold_plusminus_mult_expr): Check exact power
+       of two on the absolute value.
+       (fold_binary): Fold x * -C to -x * C if x is easily negatable
+       and negating -C does not overflow.
+
 2006-10-23  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/21032
index b04022e1086eac4b548996fc6f62d57a650c5828..571a7e84612a0126cf248b871fbe86b8c355c727 100644 (file)
@@ -6787,7 +6787,7 @@ fold_plusminus_mult_expr (enum tree_code code, tree type, tree arg0, tree arg1)
       else
        maybe_same = arg11;
 
-      if (exact_log2 (int11) > 0 && int01 % int11 == 0)
+      if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0)
         {
          alt0 = fold_build2 (MULT_EXPR, TREE_TYPE (arg00), arg00,
                              build_int_cst (TREE_TYPE (arg00),
@@ -8752,7 +8752,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
       /* (-A) - B -> (-B) - A  where B is easily negated and we can swap.  */
       if (TREE_CODE (arg0) == NEGATE_EXPR
          && (FLOAT_TYPE_P (type)
-             || (INTEGRAL_TYPE_P (type) && flag_wrapv && !flag_trapv))
+             || INTEGRAL_TYPE_P (type))
          && negate_expr_p (arg1)
          && reorder_operands_p (arg0, arg1))
        return fold_build2 (MINUS_EXPR, type, negate_expr (arg1),
@@ -8838,7 +8838,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
                /* Avoid this transformation if B is a positive REAL_CST.  */
               && (TREE_CODE (arg1) != REAL_CST
                   ||  REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1))))
-             || (INTEGRAL_TYPE_P (type) && flag_wrapv && !flag_trapv)))
+             || INTEGRAL_TYPE_P (type)))
        return fold_build2 (PLUS_EXPR, type,
                            fold_convert (type, arg0),
                            fold_convert (type, negate_expr (arg1)));
@@ -8923,6 +8923,14 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
          /* Transform x * -1 into -x.  */
          if (integer_all_onesp (arg1))
            return fold_convert (type, negate_expr (arg0));
+         /* Transform x * -C into -x * C if x is easily negatable.  */
+         if (TREE_CODE (arg1) == INTEGER_CST
+             && tree_int_cst_sgn (arg1) == -1
+             && negate_expr_p (arg0)
+             && (tem = negate_expr (arg1)) != arg1
+             && !TREE_OVERFLOW (tem))
+           return fold_build2 (MULT_EXPR, type,
+                               negate_expr (arg0), tem);
 
          /* (a * (1 << b)) is (a << b)  */
          if (TREE_CODE (arg1) == LSHIFT_EXPR
index 06d1abca1ab42996fc29a61ee0718736b4d0e280..b8b1c525dd44865558c7bd1a02d2ebed8b0ed891 100644 (file)
@@ -1,3 +1,12 @@
+2006-10-23  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/27132
+       PR middle-end/23295
+       * gcc.dg/pr27132.c: New testcase.
+       * gcc.dg/pr23295.c: Likewise.
+       * gcc.dg/tree-ssa/pr23294.c: Adjust patterns.
+       * g++.dg/tree-ssa/pr19807.C: Likewise.
+
 2006-10-23  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/21032
index 0ff10db8eb49598e71f723ddf08ecfe260517e48..d85b8ad8742b8e5912228bce2e9f1749bc51540e 100644 (file)
@@ -19,6 +19,6 @@ void bar(int i)
 }
 
 /* { dg-final { scan-tree-dump-times "&a\\\[2\\\]" 3 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "&a\\\[.* 1\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "&a\\\[.* \\+ -1\\\]" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "&a\\\[.* \\+ 1\\\]" 1 "optimized" } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/pr23295.c b/gcc/testsuite/gcc.dg/pr23295.c
new file mode 100644 (file)
index 0000000..0418964
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+int foo(int i)
+{
+  return -i - 5;
+}
+
+/* { dg-final { scan-tree-dump "-5 - i" "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */
diff --git a/gcc/testsuite/gcc.dg/pr27132.c b/gcc/testsuite/gcc.dg/pr27132.c
new file mode 100644 (file)
index 0000000..272862a
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+int foo(int i)
+{
+  return i - -1;
+}
+
+/* { dg-final { scan-tree-dump "i \\+ 1" "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */
index 35ab5786a905adcb5cae02ea125cc0d1352f1aad..d73512d7af508f39bdc2ee1cd48b7f03162caa77 100644 (file)
@@ -32,7 +32,6 @@ int f6(int a, int b)
 }
 
 /* { dg-final { scan-tree-dump-times "a \\\* 5" 3 "optimized" } } */
-/* { dg-final { scan-tree-dump "\\\(b \\\* 3 \\\+ a\\\) \\\* 2" "optimized" } } */
-/* { dg-final { scan-tree-dump "\\\(a - b \\\* 3\\\) \\\* 2" "optimized" } } */
-/* { dg-final { scan-tree-dump "\\\(a \\\* 3 - b\\\) \\\* 2" "optimized" } } */
+/* { dg-final { scan-tree-dump-times "\\\) \\\* 2" 3 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "\\\* 6" "optimized" } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */