Enable a target with FEAT_FP16 to emit the half-precision variants
of FCMP/FCMPE.

gcc/ChangeLog:

        * config/aarch64/aarch64.md: Update cbranch, cstore, fcmp
        and fcmpe to use the GPF_F16 iterator for floating-point
        modes.

gcc/testsuite/ChangeLog:

        * gcc.target/aarch64/_Float16_cmp_1.c: New test.
        * gcc.target/aarch64/_Float16_cmp_2.c: New (negative) test.
---
 gcc/config/aarch64/aarch64.md                 | 29 +++++-----
 .../gcc.target/aarch64/_Float16_cmp_1.c       | 54 +++++++++++++++++++
 .../gcc.target/aarch64/_Float16_cmp_2.c       |  7 +++
 3 files changed, 77 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/_Float16_cmp_1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/_Float16_cmp_2.c

diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 071058dbeb3..8721bf5d4f3 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -707,11 +707,12 @@
 )
 
 (define_expand "cbranch<mode>4"
-  [(set (pc) (if_then_else (match_operator 0 "aarch64_comparison_operator"
-                           [(match_operand:GPF 1 "register_operand")
-                            (match_operand:GPF 2 
"aarch64_fp_compare_operand")])
-                          (label_ref (match_operand 3 "" ""))
-                          (pc)))]
+  [(set (pc) (if_then_else
+               (match_operator 0 "aarch64_comparison_operator"
+                [(match_operand:GPF_F16 1 "register_operand")
+                 (match_operand:GPF_F16 2 "aarch64_fp_compare_operand")])
+               (label_ref (match_operand 3 "" ""))
+               (pc)))]
   ""
   "
   operands[1] = aarch64_gen_compare_reg (GET_CODE (operands[0]), operands[1],
@@ -4338,26 +4339,28 @@
 
 (define_insn "fcmp<mode>"
   [(set (reg:CCFP CC_REGNUM)
-        (compare:CCFP (match_operand:GPF 0 "register_operand")
-                     (match_operand:GPF 1 "aarch64_fp_compare_operand")))]
+       (compare:CCFP
+               (match_operand:GPF_F16 0 "register_operand")
+               (match_operand:GPF_F16 1 "aarch64_fp_compare_operand")))]
    "TARGET_FLOAT"
    {@ [ cons: 0 , 1  ]
       [ w       , Y  ] fcmp\t%<s>0, #0.0
       [ w       , w  ] fcmp\t%<s>0, %<s>1
   }
-  [(set_attr "type" "fcmp<s>")]
+  [(set_attr "type" "fcmp<stype>")]
 )
 
 (define_insn "fcmpe<mode>"
   [(set (reg:CCFPE CC_REGNUM)
-        (compare:CCFPE (match_operand:GPF 0 "register_operand")
-                      (match_operand:GPF 1 "aarch64_fp_compare_operand")))]
+       (compare:CCFPE
+               (match_operand:GPF_F16 0 "register_operand")
+               (match_operand:GPF_F16 1 "aarch64_fp_compare_operand")))]
    "TARGET_FLOAT"
    {@ [ cons: 0 , 1  ]
       [ w       , Y  ] fcmpe\t%<s>0, #0.0
       [ w       , w  ] fcmpe\t%<s>0, %<s>1
   }
-  [(set_attr "type" "fcmp<s>")]
+  [(set_attr "type" "fcmp<stype>")]
 )
 
 (define_insn "*cmp_swp_<shift>_reg<mode>"
@@ -4425,8 +4428,8 @@
 (define_expand "cstore<mode>4"
   [(set (match_operand:SI 0 "register_operand")
        (match_operator:SI 1 "aarch64_comparison_operator_mode"
-        [(match_operand:GPF 2 "register_operand")
-         (match_operand:GPF 3 "aarch64_fp_compare_operand")]))]
+        [(match_operand:GPF_F16 2 "register_operand")
+         (match_operand:GPF_F16 3 "aarch64_fp_compare_operand")]))]
   ""
   "
   operands[2] = aarch64_gen_compare_reg (GET_CODE (operands[1]), operands[2],
diff --git a/gcc/testsuite/gcc.target/aarch64/_Float16_cmp_1.c 
b/gcc/testsuite/gcc.target/aarch64/_Float16_cmp_1.c
new file mode 100644
index 00000000000..e49ace1d7dc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/_Float16_cmp_1.c
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv8.2-a+fp16" } */
+
+/*
+** test_fcmp_store:
+**     fcmp    h0, h1
+**     cset    w0, eq
+**     ret
+*/
+int
+test_fcmp_store(_Float16 a, _Float16 b)
+{
+    return a == b;
+}
+
+/*
+** test_fcmpe_store:
+**     fcmpe   h0, h1
+**     cset    w0, mi
+**     ret
+*/
+int
+test_fcmpe_store(_Float16 a, _Float16 b)
+{
+    return a < b;
+}
+
+/*
+** test_fcmp_branch:
+**     fcmp    h0, h1
+**     ...
+*/
+_Float16
+test_fcmp_branch(_Float16 a, _Float16 b)
+{
+    if (a == b)
+        return a * b;
+    return a;
+}
+
+/*
+** test_fcmpe_branch:
+**     fcmpe   h0, h1
+**     ...
+*/
+_Float16
+test_fcmpe_branch(_Float16 a, _Float16 b)
+{
+    if (a < b)
+        return a * b;
+    return a;
+}
+
+/* { dg-final { check-function-bodies "**" "" "" } } */
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.target/aarch64/_Float16_cmp_2.c 
b/gcc/testsuite/gcc.target/aarch64/_Float16_cmp_2.c
new file mode 100644
index 00000000000..e714304970b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/_Float16_cmp_2.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv8.2-a+nofp16" } */
+
+#include "_Float16_cmp_1.c"
+
+/* { dg-final { scan-assembler-not "\tfcmp\th\[0-9\]\+" } } */
+/* { dg-final { scan-assembler-not "\tfcmpe\th\[0-9\]\+" } } */
\ No newline at end of file
-- 
2.34.1

Reply via email to