This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] pr20130, fold x * -1 to -x.


 Hi,

  This patch folds x * -1 to -x.  This patch has been bootstrapped and
regtested on ia64-linux with no regressions.  The attached testcase failures
before the test and passes with the test.  Ok for mainline?

-- 
Thanks,
Jim

http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim

2005-03-08  James A. Morrison  <phython@gcc.gnu.org>

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

Index: fold-const.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.535
diff -u -p -r1.535 fold-const.c
--- fold-const.c	7 Mar 2005 21:24:21 -0000	1.535
+++ fold-const.c	9 Mar 2005 04:03:17 -0000
@@ -7795,6 +7795,9 @@ fold_binary (tree expr)
 	    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
/* { 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" } } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]