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

            Bug ID: 50118
           Summary: llvm incorrectly compiles bitshift on x86
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

clang miscompiles a bit shift at -O1 when targeting x86-64 or i386.

To reproduce, on an x86 machine:

```
#include <stdio.h>

__attribute__((noinline))
unsigned func(unsigned v0, unsigned v1, unsigned shift) {
  v1 <<= shift;
  return v1 | (v0 >> ((32u - shift) & 31u));
}

int main(void) {
  unsigned r = func(42, 0, 0);
  printf("%u\n", r);
  return 0;
}
```

Compile with `clang -O1 test.c && ./a.out`

This program should output 42, and it does so at -O0. However with -O1 it
outputs 0.

Reproes with clang 11.1 on Linux, clang 12.0 on x86 Mac. Does not repro with
clang 12 on ARM Mac. This does not repro on ARM so I'll direct to the x86
backend.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to