From: phython Date: Fri, 11 Mar 2005 03:18:56 +0000 (+0000) Subject: 2005-03-11 James A. Morrison X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=48854785d83ba49184295281e927c400d776c5d9;p=thirdparty%2Fgcc.git 2005-03-11 James A. Morrison PR tree-optimization/20130 * fold-const.c (fold): Fold x * -1 into -x. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96283 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a25ac12d6169..82d61aaafb84 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-03-11 James A. Morrison + + PR tree-optimization/20130 + * fold-const.c (fold): Fold x * -1 into -x. + 2005-03-11 Kaz Kojima PR rtl-optimization/20331 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 38fb95d5cfb2..9d0a9f02d736 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 1859326a7be9..c51d1d111063 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-03-10 James A. Morrison + + PR tree-optimization/20130 + * gcc.dg/pr20130-1.c: New test. + 2005-03-10 Steve Ellcey 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 000000000000..7097ff600eb2 --- /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" } } */