public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* inhibit the sincos optimization when the target has sin and cos instructions
@ 2016-05-13 19:19 Cesar Philippidis
  2016-05-13 19:58 ` Richard Biener
  0 siblings, 1 reply; 12+ messages in thread
From: Cesar Philippidis @ 2016-05-13 19:19 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

The cse_sincos pass tries to optimize sequences such as

  sin (x);
  cos (x);

into a single call to sincos, or cexpi, when available. However, the
nvptx target has sin and cos instructions, albeit with some loss of
precision (so it's only enabled with -ffast-math). This patch teaches
cse_sincos pass to ignore sin, cos and cexpi instructions when the
target can expand those calls. This yields a 6x speedup in 314.omriq
from spec accel when running on Nvidia accelerators.

Is this OK for trunk?

Cesar

[-- Attachment #2: inhibit-sincos.diff --]
[-- Type: text/x-patch, Size: 1473 bytes --]

2016-05-13  Cesar Philippidis  <cesar@codesourcery.com>

	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 <gcall *> (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))

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-05-19 23:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-13 19:19 inhibit the sincos optimization when the target has sin and cos instructions Cesar Philippidis
2016-05-13 19:58 ` Richard Biener
2016-05-13 20:13   ` Andrew Pinski
2016-05-17 21:10     ` Cesar Philippidis
2016-05-17 21:23       ` Andrew Pinski
2016-05-17 21:30         ` Cesar Philippidis
2016-05-18 12:29           ` Nathan Sidwell
2016-05-19  3:43             ` Cesar Philippidis
2016-05-19 11:29               ` Alexander Monakov
2016-05-19 18:42                 ` Cesar Philippidis
2016-05-19 23:30                   ` Nathan Sidwell
2016-05-19 23:12               ` Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).