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]: Handle CONJ_EXPR in negate_expr_p and fold_negate_expr


This patch handles CONJ_EXPR in negate_expr_p and fold_negate_expr.
(A CONJ_EXPR is negatable if its operand is negatable.)

Tested on sparc-sun-solaris2.10, no regressions.

Okay for mainline?

		Thanks,
		--Kaveh


2007-02-04  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* fold-const.c (negate_expr_p): Handle CONJ_EXPR.
	(fold_negate_expr): Likewise.

testsuite:
	* gcc.dg/builtins-20.c: Add more cases.

diff -rup orig/egcc-SVN20070203/gcc/fold-const.c egcc-SVN20070203/gcc/fold-const.c
--- orig/egcc-SVN20070203/gcc/fold-const.c	2007-02-03 15:09:21.000000000 -0500
+++ egcc-SVN20070203/gcc/fold-const.c	2007-02-04 13:59:18.265294102 -0500
@@ -1015,6 +1015,9 @@ negate_expr_p (tree t)
       return negate_expr_p (TREE_OPERAND (t, 0))
 	     && negate_expr_p (TREE_OPERAND (t, 1));

+    case CONJ_EXPR:
+      return negate_expr_p (TREE_OPERAND (t, 0));
+
     case PLUS_EXPR:
       if (HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type))
 	  || HONOR_SIGNED_ZEROS (TYPE_MODE (type)))
@@ -1145,6 +1148,12 @@ fold_negate_expr (tree t)
 			    fold_negate_expr (TREE_OPERAND (t, 1)));
       break;

+    case CONJ_EXPR:
+      if (negate_expr_p (t))
+	return fold_build1 (CONJ_EXPR, type,
+			    fold_negate_expr (TREE_OPERAND (t, 0)));
+      break;
+
     case NEGATE_EXPR:
       return TREE_OPERAND (t, 0);

diff -rup orig/egcc-SVN20070203/gcc/testsuite/gcc.dg/builtins-20.c egcc-SVN20070203/gcc/testsuite/gcc.dg/builtins-20.c
--- orig/egcc-SVN20070203/gcc/testsuite/gcc.dg/builtins-20.c	2007-02-02 12:46:27.000000000 -0500
+++ egcc-SVN20070203/gcc/testsuite/gcc.dg/builtins-20.c	2007-02-04 14:15:15.403290020 -0500
@@ -260,6 +260,18 @@ void test3(__complex__ double x, __compl

   if (ccos(i ? x : ctan(y/x)) != ccos(i ? -x : -ctan(-y/x)))
     link_error();
+
+  if (~x != -~-x)
+    link_error();
+
+  if (ccos(~x) != ccos(-~-x))
+    link_error();
+
+  if (ctan(~(x-y)) != -ctan(~(y-x)))
+    link_error();
+
+  if (ctan(~(x/y)) != -ctan(~(x/-y)))
+    link_error();
 }

 void test1f(float x)
@@ -467,6 +479,18 @@ void test3f(__complex__ float x, __compl

   if (ccosf(i ? x : ctanf(y/x)) != ccosf(i ? -x : -ctanf(-y/x)))
     link_error();
+
+  if (~x != -~-x)
+    link_error();
+
+  if (ccosf(~x) != ccosf(-~-x))
+    link_error();
+
+  if (ctanf(~(x-y)) != -ctanf(~(y-x)))
+    link_error();
+
+  if (ctanf(~(x/y)) != -ctanf(~(x/-y)))
+    link_error();
 }

 void test1l(long double x)
@@ -674,6 +698,18 @@ void test3l(__complex__ long double x, _

   if (ccosl(i ? x : ctanl(y/x)) != ccosl(i ? -x : -ctanl(-y/x)))
     link_error();
+
+  if (~x != -~-x)
+    link_error();
+
+  if (ccosl(~x) != ccosl(-~-x))
+    link_error();
+
+  if (ctanl(~(x-y)) != -ctanl(~(y-x)))
+    link_error();
+
+  if (ctanl(~(x/y)) != -ctanl(~(x/-y)))
+    link_error();
 }

 int main()


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