re PR tree-optimization/20130 (Fold a * -1 - 1 into ~a;)
authorJames A. Morrison <phython@gcc.gnu.org>
Fri, 11 Mar 2005 03:18:56 +0000 (03:18 +0000)
committerJames A. Morrison <phython@gcc.gnu.org>
Fri, 11 Mar 2005 03:18:56 +0000 (03:18 +0000)
2005-03-11  James A. Morrison  <phython@gcc.gnu.org>

       PR tree-optimization/20130
       * fold-const.c (fold): Fold x * -1 into -x.

From-SVN: r96283

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr20130-1.c [new file with mode: 0644]

index a25ac12d6169a78bea69c7c4b01e948ac3c31ab7..82d61aaafb849c2b9556a27fe414d6439aef3d3f 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-11  James A. Morrison  <phython@gcc.gnu.org>
+
+       PR tree-optimization/20130
+       * fold-const.c (fold): Fold x * -1 into -x.
+
 2005-03-11  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        PR rtl-optimization/20331
index 38fb95d5cfb28121f0f19e2b8142d7abb792d101..9d0a9f02d7368bc794549c2ae3dacb1bf1b51a9f 100644 (file)
@@ -7785,6 +7785,9 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
            return omit_one_operand (type, arg1, arg0);
          if (integer_onep (arg1))
            return non_lvalue (fold_convert (type, arg0));
+         /* Transform x * -1 into -x.  */
+         if (integer_all_onesp (arg1))
+           return fold_convert (type, negate_expr (arg0));
 
          /* (a * (1 << b)) is (a << b)  */
          if (TREE_CODE (arg1) == LSHIFT_EXPR
index 1859326a7be92b65487e82f4bb7e2dd84990b0d6..c51d1d111063674434e5dd226d76da4eff85cbd2 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-10  James A. Morrison  <phython@gcc.gnu.org>
+
+       PR tree-optimization/20130
+       * gcc.dg/pr20130-1.c: New test.
+
 2005-03-10  Steve Ellcey  <sje@cup.hp.com>
 
        PR target/20095
diff --git a/gcc/testsuite/gcc.dg/pr20130-1.c b/gcc/testsuite/gcc.dg/pr20130-1.c
new file mode 100644 (file)
index 0000000..7097ff6
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-generic" } */
+int z (int a) {
+       return a * -1;
+}
+
+int x (int a) {
+       return -1 * a;
+}
+
+int y (int a) {
+       return -(-1 * -a);
+}
+/* { dg-final { scan-tree-dump-times "-a" 3 "generic" } } */