[llvm-bugs] [Bug 25985] New: Bit shifting __int128 return wrong result

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 31 17:00:42 PST 2015


            Bug ID: 25985
           Summary: Bit shifting __int128 return wrong result
           Product: libraries
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: yyc1992 at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Bit shifting a `__int128` constant by (a `int64_t` variable which is) zero
returns wrong result. This is causing a test failure in julia on AArch64.

The c repro for Clang 3.7 is (including a printing that makes it easier to run)

#include <stdint.h>
#include <stdio.h>

__attribute__((noinline)) void f(__int128 *p, uint64_t i)
    /* *p = i > 127 ? 0 : ((__int128)0xffff) << i; */
    *p = ((__int128)0xffff) << i;

int main()
    union {
        struct {
            int64_t lo;
            int64_t hi;
        __int128 i128;
    } v;
    f(&v.i128, 0);
    printf("%ld, %ld\n", v.lo, v.hi);
    return 0;

When compiled with clang, this print out `65535, 65535` and when compiling with
gcc this print out `65535, 0` (<-- correct result).

ASM produced by clang (-O2)

f:                                      // @f
// BB#0:
        sub     x8, x1, #64             // =64
        orr     w9, wzr, #0xffff
        orr     w10, wzr, #0x40
        lsl     x11, x9, x8
        sub      x10, x10, x1
        cmp      x8, #0                 // =0
        lsl     x8, x9, x1
        lsr     x9, x9, x10
        csel    x8, xzr, x8, ge
        csel    x9, x11, x9, ge
        stp      x8, x9, [x0]

ASM produced by gcc (-O2)

        mvn     w4, w1
        mov     x2, 65535
        mov     x3, 32767
        lsl     x2, x2, x1
        lsr     x3, x3, x4
        ands    w1, w1, 64
        csel    x3, x3, x2, eq
        cmp     w1, wzr
        csel    x2, x2, xzr, eq
        stp     x2, x3, [x0]

LLVM IR produced by clang (-O2), which looks fine AFAICT.

define void @f(i128* nocapture %p, i64 %i) #0 {
  %1 = zext i64 %i to i128
  %2 = shl i128 65535, %1
  store i128 %2, i128* %p, align 16, !tbaa !1
  ret void

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/20160101/5d94e77c/attachment.html>

More information about the llvm-bugs mailing list