diff options
author | James A. Morrison <phython@gcc.gnu.org> | 2005-03-11 03:18:56 +0000 |
---|---|---|
committer | James A. Morrison <phython@gcc.gnu.org> | 2005-03-11 03:18:56 +0000 |
commit | 694d73e1659c7db09d415c8ba0ebeb441c0782a8 (patch) | |
tree | 2c71b62d1a54cb3df4ca245b02f729ad871db5e0 | |
parent | 550b7784c6e4fdf832cca6619f61f0c0f5935d07 (diff) | |
download | gcc-694d73e1659c7db09d415c8ba0ebeb441c0782a8.zip gcc-694d73e1659c7db09d415c8ba0ebeb441c0782a8.tar.gz gcc-694d73e1659c7db09d415c8ba0ebeb441c0782a8.tar.bz2 |
re PR tree-optimization/20130 (Fold a * -1 - 1 into ~a;)
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
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/fold-const.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr20130-1.c | 14 |
4 files changed, 27 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a25ac12..82d61aa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 38fb95d..9d0a9f0 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1859326..c51d1d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..7097ff6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr20130-1.c @@ -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" } } */ |