The following standard pattern names were implemented by simply
renaming some existing patterns:

* fnma
* fms
* fnms

I have added an extra pattern for when we don't care about
signed zero, so we can do "-fma (a,b,c)" more efficiently.

Regression testing all passed.
 
OK to commit?

Cheers,
Ian


2012-09-14  Ian Bolton  <ian.bol...@arm.com>

gcc/
        * config/aarch64/aarch64.md (fmsub<mode>4): Renamed
        to fnma<mode>4.
        * config/aarch64/aarch64.md (fnmsub<mode>4): Renamed
        to fms<mode>4.
        * config/aarch64/aarch64.md (fnmadd<mode>4): Renamed
        to fnms<mode>4.
        * config/aarch64/aarch64.md (*fnmadd<mode>4): New pattern.

testsuite/
        * gcc.target/aarch64/fmadd.c: Added extra tests.
        * gcc.target/aarch64/fnmadd-fastmath.c: New test.


diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 3fbebf7..33815ff 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -2506,7 +2506,7 @@
    (set_attr "mode" "<MODE>")]
 )
 
-(define_insn "*fmsub<mode>4"
+(define_insn "fnma<mode>4"
   [(set (match_operand:GPF 0 "register_operand" "=w")
        (fma:GPF (neg:GPF (match_operand:GPF 1 "register_operand" "w"))
                 (match_operand:GPF 2 "register_operand" "w")
@@ -2517,7 +2517,7 @@
    (set_attr "mode" "<MODE>")]
 )
 
-(define_insn "*fnmsub<mode>4"
+(define_insn "fms<mode>4"
   [(set (match_operand:GPF 0 "register_operand" "=w")
         (fma:GPF (match_operand:GPF 1 "register_operand" "w")
                 (match_operand:GPF 2 "register_operand" "w")
@@ -2528,7 +2528,7 @@
    (set_attr "mode" "<MODE>")]
 )
 
-(define_insn "*fnmadd<mode>4"
+(define_insn "fnms<mode>4"
   [(set (match_operand:GPF 0 "register_operand" "=w")
        (fma:GPF (neg:GPF (match_operand:GPF 1 "register_operand" "w"))
                 (match_operand:GPF 2 "register_operand" "w")
@@ -2539,6 +2539,18 @@
    (set_attr "mode" "<MODE>")]
 )
 
+;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
+(define_insn "*fnmadd<mode>4"
+  [(set (match_operand:GPF 0 "register_operand")
+       (neg:GPF (fma:GPF (match_operand:GPF 1 "register_operand")
+                         (match_operand:GPF 2 "register_operand")
+                         (match_operand:GPF 3 "register_operand"))))]
+  "!HONOR_SIGNED_ZEROS (<MODE>mode) && TARGET_FLOAT"
+  "fnmadd\\t%<s>0, %<s>1, %<s>2, %<s>3"
+  [(set_attr "v8type" "fmadd")
+   (set_attr "mode" "<MODE>")]
+)
+
 ;; -------------------------------------------------------------------
 ;; Floating-point conversions
 ;; -------------------------------------------------------------------
diff --git a/gcc/testsuite/gcc.target/aarch64/fmadd.c 
b/gcc/testsuite/gcc.target/aarch64/fmadd.c
index 3b55554..39975db 100644
--- a/gcc/testsuite/gcc.target/aarch64/fmadd.c
+++ b/gcc/testsuite/gcc.target/aarch64/fmadd.c
@@ -4,15 +4,52 @@
 extern double fma (double, double, double);
 extern float fmaf (float, float, float);
 
-double test1 (double x, double y, double z)
+double test_fma1 (double x, double y, double z)
 {
   return fma (x, y, z);
 }
 
-float test2 (float x, float y, float z)
+float test_fma2 (float x, float y, float z)
 {
   return fmaf (x, y, z);
 }
 
+double test_fnma1 (double x, double y, double z)
+{
+  return fma (-x, y, z);
+}
+
+float test_fnma2 (float x, float y, float z)
+{
+  return fmaf (-x, y, z);
+}
+
+double test_fms1 (double x, double y, double z)
+{
+  return fma (x, y, -z);
+}
+
+float test_fms2 (float x, float y, float z)
+{
+  return fmaf (x, y, -z);
+}
+
+double test_fnms1 (double x, double y, double z)
+{
+  return fma (-x, y, -z);
+}
+
+float test_fnms2 (float x, float y, float z)
+{
+  return fmaf (-x, y, -z);
+}
+
 /* { dg-final { scan-assembler-times "fmadd\td\[0-9\]" 1 } } */
 /* { dg-final { scan-assembler-times "fmadd\ts\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fmsub\td\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fmsub\ts\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fnmsub\td\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fnmsub\ts\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fnmadd\td\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fnmadd\ts\[0-9\]" 1 } } */
+
diff --git a/gcc/testsuite/gcc.target/aarch64/fnmadd-fastmath.c 
b/gcc/testsuite/gcc.target/aarch64/fnmadd-fastmath.c
new file mode 100644
index 0000000..9c115df
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/fnmadd-fastmath.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math" } */
+
+extern double fma (double, double, double);
+extern float fmaf (float, float, float);
+
+double test_fma1 (double x, double y, double z)
+{
+  return - fma (x, y, z);
+}
+
+float test_fma2 (float x, float y, float z)
+{
+  return - fmaf (x, y, z);
+}
+
+/* { dg-final { scan-assembler-times "fnmadd\td\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fnmadd\ts\[0-9\]" 1 } } */
+

Reply via email to