OSDN Git Service

2006-12-14 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Dec 2006 13:09:24 +0000 (13:09 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Dec 2006 13:09:24 +0000 (13:09 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119858 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-60.c [new file with mode: 0644]

index e768519..aeb9d19 100644 (file)
@@ -1,3 +1,9 @@
+2006-12-14  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.
+
 2006-12-14  Dorit Nuzman  <dorit@il.ibm.com>
            Trevor Smigiel  <trevor_smigiel@playstation.sony.com>
 
index da1bfed..751ef2e 100644 (file)
@@ -7715,6 +7715,19 @@ fold_unary (enum tree_code code, tree type, tree op0)
          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:
@@ -7741,6 +7754,19 @@ fold_unary (enum tree_code code, tree type, tree op0)
          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 7ca2395..b99415c 100644 (file)
@@ -1,3 +1,8 @@
+2006-12-14  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/30198
+       * gcc.dg/builtins-60.c: New testcase.
+
 2006-12-14  Dorit Nuzman  <dorit@il.ibm.com>
  
        * lib/target-supports.exp (vect_no_align): Remove spu.
diff --git a/gcc/testsuite/gcc.dg/builtins-60.c b/gcc/testsuite/gcc.dg/builtins-60.c
new file mode 100644 (file)
index 0000000..b57679f
--- /dev/null
@@ -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" } } */