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 COMPOUND_EXPR/COND_EXPR in fold_strip_sign_ops


This patch makes fold_strip_sign_ops handle COMPOUND_EXPR and COND_EXPR.

Tested on sparc-sun-solaris2.10, no regressions and the new tests pass.

Okay for mainline?

		Thanks,
		--Kaveh


2006-11-12  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* fold-const.c (fold_strip_sign_ops): Handle COMPOUND_EXPR and
	COND_EXPR.

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

diff -rup orig/egcc-SVN20061112/gcc/fold-const.c egcc-SVN20061112/gcc/fold-const.c
--- orig/egcc-SVN20061112/gcc/fold-const.c	2006-11-12 20:01:46.000000000 -0500
+++ egcc-SVN20061112/gcc/fold-const.c	2006-11-12 21:26:25.508067689 -0500
@@ -13360,6 +13360,22 @@ fold_strip_sign_ops (tree exp)
 			    arg1 ? arg1 : TREE_OPERAND (exp, 1));
       break;

+    case COMPOUND_EXPR:
+      arg0 = TREE_OPERAND (exp, 0);
+      arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 1));
+      if (arg1)
+	return fold_build2 (COMPOUND_EXPR, TREE_TYPE (exp), arg0, arg1);
+      break;
+
+    case COND_EXPR:
+      arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 1));
+      arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 2));
+      if (arg0 || arg1)
+	return fold_build3 (COND_EXPR, TREE_TYPE (exp), TREE_OPERAND (exp, 0),
+			    arg0 ? arg0 : TREE_OPERAND (exp, 1),
+			    arg1 ? arg1 : TREE_OPERAND (exp, 2));
+      break;
+
     case CALL_EXPR:
       /* Strip sign ops from the argument of "odd" math functions.  */
       if (negate_mathfn_p (builtin_mathfn_code (exp)))
diff -rup orig/egcc-SVN20061112/gcc/testsuite/gcc.dg/builtins-20.c egcc-SVN20061112/gcc/testsuite/gcc.dg/builtins-20.c
--- orig/egcc-SVN20061112/gcc/testsuite/gcc.dg/builtins-20.c	2006-11-10 23:20:04.000000000 -0500
+++ egcc-SVN20061112/gcc/testsuite/gcc.dg/builtins-20.c	2006-11-12 21:56:32.823868490 -0500
@@ -89,6 +89,22 @@ void test2(double x, double y)
   if (cos(-fabs(tan(x/-y))) != cos(tan(x/y)))
     link_error ();

+  if (cos(y<10 ? -x : y) != cos(y<10 ? x : y))
+    link_error ();
+
+  if (cos(y<10 ? x : -y) != cos(y<10 ? x : y))
+    link_error ();
+
+  if (cos(y<10 ? -fabs(x) : tan(x<20 ? -x : -fabs(y)))
+      != cos(y<10 ? x : tan(x<20 ? x : y)))
+    link_error ();
+
+  if (cos((y*=3, -x)) != cos((y*=3,x)))
+    link_error ();
+
+  if (cos((y*=2, -fabs(tan(x/-y)))) != cos((y*=2,tan(x/y))))
+    link_error ();
+
   if (hypot (x, 0) != fabs(x))
     link_error ();

@@ -190,6 +206,22 @@ void test2f(float x, float y)
   if (cosf(-fabsf(tanf(x/-y))) != cosf(tanf(x/y)))
     link_error ();

+  if (cosf(y<10 ? -x : y) != cosf(y<10 ? x : y))
+    link_error ();
+
+  if (cosf(y<10 ? x : -y) != cosf(y<10 ? x : y))
+    link_error ();
+
+  if (cosf(y<10 ? -fabsf(x) : tanf(x<20 ? -x : -fabsf(y)))
+      != cosf(y<10 ? x : tanf(x<20 ? x : y)))
+    link_error ();
+
+  if (cosf((y*=3, -x)) != cosf((y*=3,x)))
+    link_error ();
+
+  if (cosf((y*=2, -fabsf(tanf(x/-y)))) != cosf((y*=2,tanf(x/y))))
+    link_error ();
+
   if (hypotf (x, 0) != fabsf(x))
     link_error ();

@@ -292,6 +324,22 @@ void test2l(long double x, long double y
   if (cosl(-fabsl(tanl(x/-y))) != cosl(tanl(x/y)))
     link_error ();

+  if (cosl(y<10 ? -x : y) != cosl(y<10 ? x : y))
+    link_error ();
+
+  if (cosl(y<10 ? x : -y) != cosl(y<10 ? x : y))
+    link_error ();
+
+  if (cosl(y<10 ? -fabsl(x) : tanl(x<20 ? -x : -fabsl(y)))
+      != cosl(y<10 ? x : tanl(x<20 ? x : y)))
+    link_error ();
+
+  if (cosl((y*=3, -x)) != cosl((y*=3,x)))
+    link_error ();
+
+  if (cosl((y*=2, -fabsl(tanl(x/-y)))) != cosl((y*=2,tanl(x/y))))
+    link_error ();
+
   if (hypotl (x, 0) != fabsl(x))
     link_error ();


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