For a PowerPC target, when two parts of long double (IBM extended double / double-double / ppc_fp128) are accessed directly and their values are visible to the optimizer, they are swapped:
include
include
attribute((optnone)) // imagine it in a separate TU
static void opaque(void p) { return p; }
int main()
{
long double d = 1;
unsigned long l[2];
memcpy(&l, &d, sizeof d);
printf("%016lx %016lx\n", l[0], l[1]);
opaque(&l); // hide it from the optimizer
printf("%016lx %016lx\n", l[0], l[1]);
| | |
| --- | --- |
| Bugzilla Link | [45137](https://llvm.org/bz45137) |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
## Extended Description
For a PowerPC target, when two parts of long double (IBM extended double / double-double / ppc_fp128) are accessed directly and their values are visible to the optimizer, they are swapped:
----------------------------------------------------------------------
#include <string.h>
#include <stdio.h>
__attribute__((optnone)) // imagine it in a separate TU
static void *opaque(void *p) { return p; }
int main()
{
long double d = 1;
unsigned long l[2];
memcpy(&l, &d, sizeof d);
printf("%016lx %016lx\n", l[0], l[1]);
opaque(&l); // hide it from the optimizer
printf("%016lx %016lx\n", l[0], l[1]);
}
----------------------------------------------------------------------
$ clang -target ppc64-linux-gnu -std=c11 -Weverything test.c && qemu-ppc64 /usr/powerpc-linux-gnu/lib64/ld64.so.1 --library-path /usr/powerpc-linux-gnu/lib64 ./a.out
3ff0000000000000 0000000000000000
3ff0000000000000 0000000000000000
$ clang -target ppc64-linux-gnu -std=c11 -Weverything -O3 test.c && qemu-ppc64 /usr/powerpc-linux-gnu/lib64/ld64.so.1 --library-path /usr/powerpc-linux-gnu/lib64 ./a.out
0000000000000000 3ff0000000000000
3ff0000000000000 0000000000000000
----------------------------------------------------------------------
clang x86-64 version: clang version 11.0.0 (https://github.com/llvm/llvm-project feb20a159410dfec4055428911c7eb2bc908cf12)
----------------------------------------------------------------------
The output line "0000000000000000 3ff0000000000000" is wrong.
Extended Description
For a PowerPC target, when two parts of long double (IBM extended double / double-double / ppc_fp128) are accessed directly and their values are visible to the optimizer, they are swapped:
include
include
attribute((optnone)) // imagine it in a separate TU static void opaque(void p) { return p; }
int main() { long double d = 1;
}
$ clang -target ppc64-linux-gnu -std=c11 -Weverything test.c && qemu-ppc64 /usr/powerpc-linux-gnu/lib64/ld64.so.1 --library-path /usr/powerpc-linux-gnu/lib64 ./a.out 3ff0000000000000 0000000000000000 3ff0000000000000 0000000000000000 $ clang -target ppc64-linux-gnu -std=c11 -Weverything -O3 test.c && qemu-ppc64 /usr/powerpc-linux-gnu/lib64/ld64.so.1 --library-path /usr/powerpc-linux-gnu/lib64 ./a.out 0000000000000000 3ff0000000000000 3ff0000000000000 0000000000000000
clang x86-64 version: clang version 11.0.0 (https://github.com/llvm/llvm-project feb20a159410dfec4055428911c7eb2bc908cf12)
The output line "0000000000000000 3ff0000000000000" is wrong.