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] Fix PR30198, fold builtin cexpi


We can fold __real cexpi () and __imag cexpi () to cos / sin.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Will commit later to mainline.

Richard.

2006-12-13  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/30198
	* fold-const.c (fold_unary): Fold REALPART_EXPR of cexpi to cos.
	Fold IMAGPART_EXPR of cexpi to sin.

	* gcc.dg/builtins-60.c: New testcase.

Index: testsuite/gcc.dg/builtins-60.c
===================================================================
*** testsuite/gcc.dg/builtins-60.c	(revision 0)
--- testsuite/gcc.dg/builtins-60.c	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do compile } */
+ /* { dg-options "-fdump-tree-gimple" } */
+ 
+ double test1 (double x)
+ {
+   return __real __builtin_cexpi (x);
+ }
+ 
+ double test2 (double x)
+ {
+   return __imag __builtin_cexpi (x);
+ }
+ 
+ /* { dg-final { scan-tree-dump "cos" "gimple" } } */
+ /* { dg-final { scan-tree-dump "sin" "gimple" } } */
+ /* { dg-final { cleanup-tree-dump "gimple" } } */
Index: fold-const.c
===================================================================
*** fold-const.c	(revision 119828)
--- fold-const.c	(working copy)
*************** fold_unary (enum tree_code code, tree ty
*** 7715,7720 ****
--- 7715,7733 ----
  	  tem = fold_build1 (REALPART_EXPR, itype, TREE_OPERAND (arg0, 0));
  	  return fold_convert (type, tem);
  	}
+       if (TREE_CODE (arg0) == CALL_EXPR)
+ 	{
+ 	  tree fn = get_callee_fndecl (arg0);
+ 	  if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
+ 	    switch (DECL_FUNCTION_CODE (fn))
+ 	      {
+ 	      CASE_FLT_FN (BUILT_IN_CEXPI):
+ 	        fn = mathfn_built_in (type, BUILT_IN_COS);
+ 	        return build_function_call_expr (fn, TREE_OPERAND (arg0, 1));
+ 
+ 	      default:;
+ 	      }
+ 	}
        return NULL_TREE;
  
      case IMAGPART_EXPR:
*************** fold_unary (enum tree_code code, tree ty
*** 7741,7746 ****
--- 7754,7772 ----
  	  tem = fold_build1 (IMAGPART_EXPR, itype, TREE_OPERAND (arg0, 0));
  	  return fold_convert (type, negate_expr (tem));
  	}
+       if (TREE_CODE (arg0) == CALL_EXPR)
+ 	{
+ 	  tree fn = get_callee_fndecl (arg0);
+ 	  if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
+ 	    switch (DECL_FUNCTION_CODE (fn))
+ 	      {
+ 	      CASE_FLT_FN (BUILT_IN_CEXPI):
+ 	        fn = mathfn_built_in (type, BUILT_IN_SIN);
+ 	        return build_function_call_expr (fn, TREE_OPERAND (arg0, 1));
+ 
+ 	      default:;
+ 	      }
+ 	}
        return NULL_TREE;
  
      default:


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