public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][AArch64] PR target/66731 Fix fnmul insn with -frounding-math
@ 2015-07-06  8:20 Szabolcs Nagy
  2015-07-06 10:24 ` James Greenhalgh
  2015-07-06 15:39 ` Marcus Shawcroft
  0 siblings, 2 replies; 9+ messages in thread
From: Szabolcs Nagy @ 2015-07-06  8:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ramana Radhakrishnan, Marcus Shawcroft

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

fnmul was modeled as (-a)*b instead of -(a*b), which is wrong with
-frounding-math, so the correct pattern is added too and the other
one is only used if !flag_rounding_math.

This affects a glibc math test, similar fix will be needed for ARM.

Tested with aarch64-none-linux-gnu cross compiler.
is this OK?

gcc/Changelog:

2015-07-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/aarch64/aarch64.md (fnmul<mode>3): Handle -frounding-math.

gcc/testsuite/Changelog:

2015-07-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* gcc.target/aarch64/fnmul-1.c: New.
	* gcc.target/aarch64/fnmul-2.c: New.
	* gcc.target/aarch64/fnmul-3.c: New.
	* gcc.target/aarch64/fnmul-4.c: New.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fnmul-2.diff --]
[-- Type: text/x-patch; name=fnmul-2.diff, Size: 3274 bytes --]

diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 2d56a75..1e343fa 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4175,6 +4175,16 @@
         (mult:GPF
 		 (neg:GPF (match_operand:GPF 1 "register_operand" "w"))
 		 (match_operand:GPF 2 "register_operand" "w")))]
+  "TARGET_FLOAT && !flag_rounding_math"
+  "fnmul\\t%<s>0, %<s>1, %<s>2"
+  [(set_attr "type" "fmul<s>")]
+)
+
+(define_insn "*fnmul<mode>3"
+  [(set (match_operand:GPF 0 "register_operand" "=w")
+        (neg:GPF (mult:GPF
+		 (match_operand:GPF 1 "register_operand" "w")
+		 (match_operand:GPF 2 "register_operand" "w"))))]
   "TARGET_FLOAT"
   "fnmul\\t%<s>0, %<s>1, %<s>2"
   [(set_attr "type" "fmul<s>")]
diff --git a/gcc/testsuite/gcc.target/aarch64/fnmul-1.c b/gcc/testsuite/gcc.target/aarch64/fnmul-1.c
new file mode 100644
index 0000000..7ec38e0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fnmul-1.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+double
+foo_d (double a, double b)
+{
+	/* { dg-final { scan-assembler "fnmul\\td\[0-9\]+, d\[0-9\]+, d\[0-9\]+" } } */
+	return -a * b;
+}
+
+float
+foo_s (float a, float b)
+{
+	/* { dg-final { scan-assembler "fnmul\\ts\[0-9\]+, s\[0-9\]+, s\[0-9\]+" } } */
+	return -a * b;
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/fnmul-2.c b/gcc/testsuite/gcc.target/aarch64/fnmul-2.c
new file mode 100644
index 0000000..f05ee79
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fnmul-2.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -frounding-math" } */
+
+double
+foo_d (double a, double b)
+{
+	/* { dg-final { scan-assembler "fneg\\td\[0-9\]+, d\[0-9\]+" } } */
+	/* { dg-final { scan-assembler "fmul\\td\[0-9\]+, d\[0-9\]+, d\[0-9\]+" } } */
+	return -a * b;
+}
+
+float
+foo_s (float a, float b)
+{
+	/* { dg-final { scan-assembler "fneg\\ts\[0-9\]+, s\[0-9\]+" } } */
+	/* { dg-final { scan-assembler "fmul\\ts\[0-9\]+, s\[0-9\]+, s\[0-9\]+" } } */
+	return -a * b;
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/fnmul-3.c b/gcc/testsuite/gcc.target/aarch64/fnmul-3.c
new file mode 100644
index 0000000..301e9cd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fnmul-3.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+double
+foo_d (double a, double b)
+{
+	/* { dg-final { scan-assembler "fnmul\\td\[0-9\]+, d\[0-9\]+, d\[0-9\]+" } } */
+	return -(a * b);
+}
+
+float
+foo_s (float a, float b)
+{
+	/* { dg-final { scan-assembler "fnmul\\ts\[0-9\]+, s\[0-9\]+, s\[0-9\]+" } } */
+	return -(a * b);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/fnmul-4.c b/gcc/testsuite/gcc.target/aarch64/fnmul-4.c
new file mode 100644
index 0000000..9b9bf1b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fnmul-4.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -frounding-math" } */
+
+double
+foo_d (double a, double b)
+{
+	/* { dg-final { scan-assembler "fnmul\\td\[0-9\]+, d\[0-9\]+, d\[0-9\]+" } } */
+	return -(a * b);
+}
+
+float
+foo_s (float a, float b)
+{
+	/* { dg-final { scan-assembler "fnmul\\ts\[0-9\]+, s\[0-9\]+, s\[0-9\]+" } } */
+	return -(a * b);
+}

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

end of thread, other threads:[~2015-08-04  9:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-06  8:20 [PATCH][AArch64] PR target/66731 Fix fnmul insn with -frounding-math Szabolcs Nagy
2015-07-06 10:24 ` James Greenhalgh
2015-07-16 10:11   ` Szabolcs Nagy
2015-08-04  9:37     ` Szabolcs Nagy
2015-08-04  9:55     ` James Greenhalgh
2015-07-06 15:39 ` Marcus Shawcroft
2015-07-09 14:40   ` Szabolcs Nagy
2015-07-15  8:34     ` Ramana Radhakrishnan
2015-07-15  9:26       ` Szabolcs Nagy

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