diff options
author | Tom de Vries <tdevries@suse.de> | 2020-09-11 05:40:36 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2020-09-11 07:27:54 +0200 |
commit | 60e537a026c037d8f3e5678acd148f9e44b4fb9c (patch) | |
tree | 7ff10798396325141304df53bfd180a4342fbbf9 | |
parent | 848e74bea1e8031925d3efe2d85b555a3cf8db38 (diff) | |
download | gcc-60e537a026c037d8f3e5678acd148f9e44b4fb9c.zip gcc-60e537a026c037d8f3e5678acd148f9e44b4fb9c.tar.gz gcc-60e537a026c037d8f3e5678acd148f9e44b4fb9c.tar.bz2 |
[nvptx] Fix printing of 128-bit constant (negative case)
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.
-rw-r--r-- | gcc/config/nvptx/nvptx.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/nvptx/int128.c | 15 |
2 files changed, 19 insertions, 1 deletions
diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index ffcbe59..4fca0ed 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -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 index 0000000..069dbbf --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/int128.c @@ -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; +} |