<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/95954>95954</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            AArch64 backend miscompiling a non-byte-sized rotate
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            llvm:codegen,
            miscompilation
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          regehr
      </td>
    </tr>
</table>

<pre>
    I believe we're miscompiling this:
```llvm
@a = external global i31

declare i31 @llvm.fshr.i31 (i31 %a, i31 %b, i31 %c)

define i31 @f() {
  %1 = load i31, ptr @a, align 1
  %r = call i31 @llvm.fshr.i31(i31 %1, i31 %1, i31 1)
  ret i31 %r
}
```
the result is:
```
_f:      
        adrp    x8, _a@GOTPAGE
        ldr     x8, [x8, _a@GOTPAGEOFF]
        ldr     w8, [x8]
        lsr     w9, w8, #1
        orr     w0, w9, w8, lsl #30
        ret
```
but that `orr` seems to be bringing in some garbage, I'll illustrate with this driver:
```c
#include <stdio.h>

extern "C" unsigned f();

unsigned a = 3;

int main() {
  printf("%x\n", f() & 0x7fffffff);
}
```
running it, we get:
```
Johns-MacBook-Pro:iN-stress regehr$ ~/llvm-project/for-alive/bin/llc test_31.aarch64.ll
Johns-MacBook-Pro:iN-stress regehr$ clang++ driver.cpp test_31.aarch64.s 
Johns-MacBook-Pro:iN-stress regehr$ ./a.out 
40000001
Johns-MacBook-Pro:iN-stress regehr$ 
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU2TozgM_TXKRRUKBAQ4cMjHZGq2anfmsPcpAwp4x7FTtunu2cP-9i0MQ6c_5tBUKrGlx5MsPSvCOdlr5hryA-SnjRj9YGxtuefBbhrT_ay_YMNK8gPjIwMVlvEqXWuuN6mk7tEP0kG6h_gE8R528fxR6uG6mLJYIKQn5CfPVguFvTKNUCjT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