re PR middle-end/30198 (__real / __imag cexpi (x) can be folded to cos (x) / sin (x))

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.

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

From-SVN: r119858
This commit is contained in:
Richard Guenther 2006-12-14 13:09:24 +00:00 committed by Richard Biener
parent bbea461bd9
commit 85aef79f75
4 changed files with 53 additions and 0 deletions

View 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>

View 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:

View 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.

View File

@ -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" } } */