[llvm-bugs] [Bug 45137] New: Wrong optimization: two parts of ppc_fp128 are swapped

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 6 08:38:11 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=45137

            Bug ID: 45137
           Summary: Wrong optimization: two parts of ppc_fp128 are swapped
           Product: new-bugs
           Version: trunk
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ch3root at openwall.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200306/90b3d109/attachment.html>


More information about the llvm-bugs mailing list