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

    <tr>
        <th>Summary</th>
        <td>
            AArch64 backend miscompile of some funnel shifts
        </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>
    this function is getting miscompiled by the AArch64 backend:
```
source_filename = "fuzz"

define noundef i15 @f(i15 %0) {
  %2 = call i15 @llvm.fshr.i15(i15 %0, i15 %0, i15 12)
 %3 = call i15 @llvm.fshl.i15(i15 %2, i15 %2, i15 11)
  ret i15 %3
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i15 @llvm.fshr.i15(i15, i15, i15) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i15 @llvm.fshl.i15(i15, i15, i15) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

let's work through it. call `f(3)` which gives us a `fshr(3, 3, 12)` which comes down to:

`000000000000011 000000000000011 >> 12` =
`000000000000000 000000000011000` = 
`000000000011000`

now we do the funnel shift left of that value by 11, giving:

`000000000011000 000000000011000 << 11` =
`100000000000001 100000000000000` =
`100000000000001` =
16385

so that's what's supposed to happen. but the AArch64 backend gives:

```
_f:
        lsr     w8, w0, #8
        bfi     w8, w0, #7, #25
        mov     w0, w8
        ret
```

when passed 3 as an argument, this gives 384

cc @nunoplopes @nbushehri 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVVmPozgQ_jXOS2kiY4frgYd0evI3RgYK8I6xkY9GPb9-ZZOzp7dXK-3DRBEY1-HvK9chnJOjRmxI_kLy150IfjK2sTjiZHet6d8bP0kHQ9Cdl0aDdDCi91KPMEvXmXmR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