2016-05-17 Cesar Philippidis gcc/ * config/nvptx/nvptx.md (sincossf3): New pattern. gcc/testsuite/ * gcc.target/nvptx/sincos-1.c: New test. * gcc.target/nvptx/sincos-2.c: New test. diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index 33a4862..29642ec 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -794,6 +794,20 @@ "" "%.\\tsqrt%#%t0\\t%0, %1;") +(define_expand "sincossf3" + [(set (match_operand:SF 0 "nvptx_register_operand" "=R") + (unspec:SF [(match_operand:SF 2 "nvptx_register_operand" "R")] + UNSPEC_COS)) + (set (match_operand:SF 1 "nvptx_register_operand" "=R") + (unspec:SF [(match_dup 2)] UNSPEC_SIN))] + "flag_unsafe_math_optimizations" +{ + emit_insn (gen_sinsf2 (operands[1], operands[2])); + emit_insn (gen_cossf2 (operands[0], operands[2])); + + DONE; +}) + (define_insn "sinsf2" [(set (match_operand:SF 0 "nvptx_register_operand" "=R") (unspec:SF [(match_operand:SF 1 "nvptx_register_operand" "R")] diff --git a/gcc/testsuite/gcc.target/nvptx/sincos-1.c b/gcc/testsuite/gcc.target/nvptx/sincos-1.c new file mode 100644 index 0000000..921ec41 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/sincos-1.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/testsuite/gcc.target/nvptx/sincos-2.c b/gcc/testsuite/gcc.target/nvptx/sincos-2.c new file mode 100644 index 0000000..b617a7c --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/sincos-2.c @@ -0,0 +1,30 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -ffast-math" } */ + +#include + +extern float sinf (float); +extern float cosf (float); + +float val = 1.0; + +float +test_sincos (float x, float other_cos) +{ + float s = sinf (x); + float c = cosf (x); + + assert (c == other_cos); + + return s + c; +} + +int +main () +{ + float c = cosf (val); + + test_sincos (val, c); + + return 0; +}