[nvptx] Fix printing of 128-bit constant (negative case)
authorTom de Vries <tdevries@suse.de>
Fri, 11 Sep 2020 03:40:36 +0000 (05:40 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 11 Sep 2020 05:27:54 +0000 (07:27 +0200)
For this code:
...
__int128 min_one = -1;
...
we currently generate:
...
.visible .global .align 8 .u64 min_one[2] = { -1, 0 };
...

Fix this in nvptx_assemble_value, such that we have instead:
...
.visible .global .align 8 .u64 min_one[2] = { -1, -1 };
...

gcc/ChangeLog:

* config/nvptx/nvptx.c (nvptx_assemble_value): Handle negative
__int128.

gcc/testsuite/ChangeLog:

* gcc.target/nvptx/int128.c: New test.

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

index ffcbe59..4fca0ed 100644 (file)
@@ -2050,13 +2050,16 @@ output_init_frag (rtx sym)
 static void
 nvptx_assemble_value (unsigned HOST_WIDE_INT val, unsigned size)
 {
+  bool negative_p
+    = val & (HOST_WIDE_INT_1U << (HOST_BITS_PER_WIDE_INT - 1));
+
   val &= ((unsigned  HOST_WIDE_INT)2 << (size * BITS_PER_UNIT - 1)) - 1;
 
   for (unsigned part = 0; size; size -= part)
     {
       if (part * BITS_PER_UNIT == HOST_BITS_PER_WIDE_INT)
        /* Avoid undefined behaviour.  */
-       val = 0;
+       val = negative_p ? -1 : 0;
       else
        val >>= (part * BITS_PER_UNIT);
       part = init_frag.size - init_frag.offset;
diff --git a/gcc/testsuite/gcc.target/nvptx/int128.c b/gcc/testsuite/gcc.target/nvptx/int128.c
new file mode 100644 (file)
index 0000000..069dbbf
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+/* { dg-additional-options "-Wno-pedantic" } */
+
+__int128 one = 1;
+__int128 min_one = -1;
+__int128 zero = 0;
+
+int
+main (void)
+{
+  if (zero - one != min_one)
+    __builtin_abort ();
+
+  return 0;
+}