2016-05-13 Cesar Philippidis gcc/ * tree-ssa-math-opts.c (pass_cse_sincos::execute): Don't optimize sin and cos calls when the target has instructions for them. gcc/testsuite/ * gcc.target/nvptx/sincos.c: New test. diff --git a/gcc/testsuite/gcc.target/nvptx/sincos.c b/gcc/testsuite/gcc.target/nvptx/sincos.c new file mode 100644 index 0000000..921ec41 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/sincos.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math" } */ + +extern float sinf (float); +extern float cosf (float); + +float +sincos_add (float x) +{ + float s = sinf (x); + float c = cosf (x); + + return s + c; +} + +/* { dg-final { scan-assembler-times "sin.approx.f32" 1 } } */ +/* { dg-final { scan-assembler-times "cos.approx.f32" 1 } } */ diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 81688cd..38051e1 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1806,6 +1806,11 @@ pass_cse_sincos::execute (function *fun) CASE_CFN_COS: CASE_CFN_SIN: CASE_CFN_CEXPI: + /* Don't modify these calls if they can be translated + directly into hardware instructions. */ + if (replacement_internal_fn (as_a (stmt)) + != IFN_LAST) + break; /* Make sure we have either sincos or cexp. */ if (!targetm.libc_has_function (function_c99_math_complex) && !targetm.libc_has_function (function_sincos))