Documentation link:
The following code is miscompiled:
#include <stdio.h>
int main(void)
{
int c1, c;
asm ("mov $1, %[c1]\n"
"mov $2, %[c]"
: [c1] "=r" (c1),
[c] "=r" (c));
printf("1=%d 2=%d\n", c1, c);
}
$ nvc --version
nvc 22.11-0 64-bit target on x86-64 Linux -tp skylake-avx512
NVIDIA Compilers and Tools
Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
$ nvc asm.c
$ ./a.out
1=2 2=2002284504
(or some other random number, expected is 1=1, 2=2, GCC, Clang, Intel all give you that)
the generated code has
41: be 01 00 00 00 mov $0x1,%esi
46: be 02 00 00 00 mov $0x2,%esi
ie. the wrong register is used for c, as it’s the same one as used for c2.
This issue came up trying to compile BLIS (GitHub - flame/blis: BLAS-like Library Instantiation Software Framework); NVHPC 22.7 had issues with the use of the rbp register in inline asm; 22.11 no longer has that issue but instead causes segmentation faults in its tests.
A workaround is to simply replace “c” by “c2”, it only seems to happen if one alias’ first letter(s) are the same as the full name of another one?