<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - llvm incorrectly compiles bitshift on x86"
   href="https://bugs.llvm.org/show_bug.cgi?id=50118">50118</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm incorrectly compiles bitshift on x86
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>corydoras@ridiculousfish.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>