MIPS: Add pattern for clo
authorJunxian Zhu <zhujunxian@oss.cipunited.com>
Fri, 17 Feb 2023 08:35:56 +0000 (16:35 +0800)
committerYunQiang Su <yunqiang.su@cipunited.com>
Fri, 24 Feb 2023 03:25:32 +0000 (11:25 +0800)
gcc/ChangeLog:

* config/mips/mips.md (*clo<mode>2): New pattern.

gcc/testsuite/ChangeLog:

* gcc.target/mips/clz.c: New test.
* gcc.target/mips/clo.c: New test.
* gcc.target/mips/mips.exp: New option HAS_CLZ.

Signed-off-by: Junxian Zhu <zhujunxian@oss.cipunited.com>
gcc/config/mips/mips.md
gcc/testsuite/gcc.target/mips/clo.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/clz.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/mips.exp

index f881a8b..ac1d77a 100644 (file)
   [(set_attr "type" "clz")
    (set_attr "mode" "<MODE>")])
 
+
+(define_insn "*clo<mode>2"
+  [(set (match_operand:GPR 0 "register_operand" "=d")
+       (clz:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))))]
+  "ISA_HAS_CLZ_CLO"
+  "<d>clo\t%0,%1"
+  [(set_attr "type" "clz")
+   (set_attr "mode" "<MODE>")])
+
 ;;
 ;;  ...................
 ;;
diff --git a/gcc/testsuite/gcc.target/mips/clo.c b/gcc/testsuite/gcc.target/mips/clo.c
new file mode 100644 (file)
index 0000000..91f29a1
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "(HAS_CLZ)" } */
+/* { dg-skip-if "code quality test" { *-*-* } { "-O0" } { "" } } */
+
+NOMIPS16 unsigned int foo(unsigned int x)
+{
+  return  __builtin_clz (~x);
+}
+
+/* { dg-final { scan-assembler-not "\tclz\t" } } */
+/* { dg-final { scan-assembler "\tclo\t" } } */
diff --git a/gcc/testsuite/gcc.target/mips/clz.c b/gcc/testsuite/gcc.target/mips/clz.c
new file mode 100644 (file)
index 0000000..74e6edb
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "(HAS_CLZ)" } */
+/* { dg-skip-if "code quality test" { *-*-* } { "-O0" } { "" } } */
+
+NOMIPS16 unsigned int foo(unsigned int x)
+{
+  return  __builtin_clz (x);
+}
+
+/* { dg-final { scan-assembler "\tclz\t" } } */
index 025fbe7..ac3ab12 100644 (file)
@@ -252,6 +252,7 @@ set mips_option_groups {
     warnings "-w"
     dump "-fdump-.*"
     ins "HAS_INS"
+       clz "HAS_CLZ"
     dmul "NOT_HAS_DMUL"
     ldc "HAS_LDC"
     movn "HAS_MOVN"
@@ -1198,11 +1199,13 @@ proc mips-dg-options { args } {
        #
         #   - paired-single instructions(*)
         #   - odd numbered single precision registers
+               #   - clz clo instructions
         #
        # (*) Note that we don't support MIPS V at the moment.
        } elseif { $isa_rev < 1
                   && ([mips_have_test_option_p options "-mpaired-single"]
                       || ([mips_have_test_option_p options "-modd-spreg"]
+                          || [mips_have_test_option_p options "HAS_CLZ"]
                           && ![mips_have_test_option_p options "-mfp64"]))} {
            if { $gp_size == 32 } {
                mips_make_test_option options "-mips32"