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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Missed optimization for sdiv by const
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Currently, aarch64 doesn't optimize sdiv by 3 as much as it could:
https://godbolt.org/z/oKWbdjhvz

@jayfoad pointed this out in this [issue](https://github.com/llvm/llvm-project/pull/189287#issuecomment-4343813987) that this can be:

```asm
sdiv3:                                  // @sdiv3
        mov     w8, #21846
        movk    w8, #21845, lsl #16
        smull   x8, w0, w8
        lsr     x8, x8, #32
        add     x0, x8, x8, lsr #31 # since x>>63 is x>>32>>31
        ret
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUU01v4yAQ_TXjC2oEg7HNwYf0I5fV3lbaM1-JabGJDE6b_voVdtOuelmthWYGvfFjGN6olPxpcq4HcQ_isVJLHuLc_1IvKg3e26hdpaO99g_LPLsphyvgA1FqNkNTExtdmgDbTOI5-9G_O5KsvxB9JZyoRMbFDMX7TExcggW-B7ofcj6nEuIB8HCKVseQd3E-AR7eAQ_xx29tn4fLO9CSDjV9VtdjVJaco5-ysyQPPpG4ZOKnLQZx71NaHIhHwO7bAT4Pi96ZOAIeQrjc3N15js_OZMDDeQkB8MA6iV0LyFcuE8fRTfmu5jXvGJcFkSQPKm9nGjUR7bYrldXQbak0At2XPnDge_LPb6uSQE23fwqbHOMFqHztSrcBObKubj6Rl--QKHFIoezZR14ay6WofFsTX-lquw0Laf5E3m5EHDdQWVtA-gVuNqR5TWPFkuQn48gb8CfgTw0nPt02HD882_hml_9uT2V7biWXqnI9a9tWCC4bUQ19Q4_aMtZwqoVyraw7U2uURtpja1TXVb5Hig2tOWUoJIqdOTLJURva2JoxzaCmblQ-7MrzFkFV60P2TAradlVQ2oW0Kh1xcq9kkwxiEf7cr5rQyylBTYNPOX3RZJ_DOiL7_Sp8EI_kp0_J2ZvwVfZxIsc4fw6AiVPK1TKH_r_luNaViiC3wi89_gkAAP__zd4SMA">