nvptx: Support 16-bit shifts and extendqihi2
authorTom de Vries <tdevries@suse.de>
Tue, 28 Jul 2020 13:13:54 +0000 (15:13 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 28 Jul 2020 13:13:54 +0000 (15:13 +0200)
Add support for 16-bits shifts and for sign extension from 8 bits to
16 bits.

This patch has been tested on nvptx-none with no new regressions.

2020-07-28  Roger Sayle  <roger@nextmovesoftware.com>
    Tom de Vries  <tdevries@suse.de>

gcc/ChangeLog:

* config/nvptx/nvptx.md (extendqihi2): New instruction.
(ashl<mode>3, ashr<mode>3, lshr<mode>3): Support HImode.

gcc/testsuite/ChangeLog:

* gcc.target/nvptx/cvt.c: New test.
* gcc.target/nvptx/shift16.c: New test.

gcc/config/nvptx/nvptx.md
gcc/testsuite/gcc.target/nvptx/cvt.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/shift16.c [new file with mode: 0644]

index 6545b81f948daf84685e4ab66699c79a6da2215b..0538e834a4c263a75c9201724d5a71e0f5494192 100644 (file)
    %.\\tld%A1%u1\\t%0, %1;"
   [(set_attr "subregs_ok" "true")])
 
+(define_insn "extendqihi2"
+  [(set (match_operand:HI 0 "nvptx_register_operand" "=R")
+       (sign_extend:HI (match_operand:QI 1 "nvptx_register_operand" "R")))]
+  ""
+  "%.\\tcvt.s16.s8\\t%0, %1;"
+  [(set_attr "subregs_ok" "true")])
+
 (define_insn "extend<mode>si2"
   [(set (match_operand:SI 0 "nvptx_register_operand" "=R,R")
        (sign_extend:SI (match_operand:QHIM 1 "nvptx_nonimmediate_operand" "R,m")))]
 ;; Shifts
 
 (define_insn "ashl<mode>3"
-  [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
-       (ashift:SDIM (match_operand:SDIM 1 "nvptx_register_operand" "R")
-                    (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
+  [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
+       (ashift:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
+                     (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
   ""
   "%.\\tshl.b%T0\\t%0, %1, %2;")
 
 (define_insn "ashr<mode>3"
-  [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
-       (ashiftrt:SDIM (match_operand:SDIM 1 "nvptx_register_operand" "R")
-                      (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
+  [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
+       (ashiftrt:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
+                       (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
   ""
   "%.\\tshr.s%T0\\t%0, %1, %2;")
 
 (define_insn "lshr<mode>3"
-  [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
-       (lshiftrt:SDIM (match_operand:SDIM 1 "nvptx_register_operand" "R")
-                      (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
+  [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
+       (lshiftrt:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
+                       (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
   ""
   "%.\\tshr.u%T0\\t%0, %1, %2;")
 
diff --git a/gcc/testsuite/gcc.target/nvptx/cvt.c b/gcc/testsuite/gcc.target/nvptx/cvt.c
new file mode 100644 (file)
index 0000000..279ec16
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do assemble } */
+/* { dg-options "-O2 -save-temps" } */
+
+signed short s;
+signed char c;
+
+void
+foo (void)
+{
+  s = c;
+}
+
+/* { dg-final { scan-assembler "(?n)cvt\\.s16\\.s8.*%r" } } */
diff --git a/gcc/testsuite/gcc.target/nvptx/shift16.c b/gcc/testsuite/gcc.target/nvptx/shift16.c
new file mode 100644 (file)
index 0000000..185aa62
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do assemble } */
+/* { dg-options "-O2 -save-temps" } */
+
+void
+foo (unsigned short u)
+{
+  volatile unsigned short u2 = u << 5;
+}
+
+void
+foo2 (short s)
+{
+  volatile unsigned short s2 = s << 5;
+}
+
+void
+foo3 (unsigned short u)
+{
+  volatile unsigned short u2 = u >> 5;
+}
+
+void
+foo4 (signed short s)
+{
+  volatile signed short s2 = s >> 5;
+}
+
+/* { dg-final { scan-assembler-times "(?n)shl\\.b16.*%r" 2 } } */
+/* { dg-final { scan-assembler "(?n)shr\\.u16.*%r" } } */
+/* { dg-final { scan-assembler "(?n)shr\\.s16.*%r" } } */