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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Special optimazation for sdiv 2
        </td>
    </tr>

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

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

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

<pre>
    * test: https://gcc.godbolt.org/z/j4EqrToT7
```
int foo_int2 (int diff) {
 diff = diff  / 2;
   return diff;
}
```
> When I take a look at the issue [PR97821](https://github.com/llvm/llvm-project/issues/97821), I find gcc has some special addressing for **sdiv 2**, so we can also enhance this case.

* **gcc**: 2 instructions
```
foo_int2:
 add     w0, w0, w0, lsr 31
        asr     w0, w0, 1
 ret
```

* **llvm**: 3 instructions
```
foo_int2: // @foo_int2
        cmp     w0, #0
        cinc w8, w0, lt
        asr     w0, w8, #1
        ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE9v2z4M_TT0hfgFDmVH9sEH95ca6G3YCuw4KJJsq3WkTJITrJ9-8J90XVoMGCYYskTRT3zko0UIprNaV5DfAdG5VW0LRJDvEzHG3vlqNiUHp35UQDVGHSKwGvsYTwFYDdQANZ2Um86pgxvixvkOqHkBap6y--_-0T1ySPeQ1rBL12feGhuxde6bsZEQqJj2ykzXlwj8bnGaLQhsvywQqEECdj1F9DqO3i4fXs3A9x_eCOwev_ba4gNG8axR4ODcM4qIsddoQhg1Qn736XPJC9pCvgcqbnia2I-HjXRHoGYYztfXfyfvnrSMQM0ME4CaBYRKoP_xAVtjFXZSYi8CBnfUGE5aGjGgUMrrEIztsHUegWqgOihzRlrWE0BweNEohUUxBIfa9sJKjbE3AaUIerMyXGaqV5hOyhWD1UhobIh-lNE4Gz7M0LUeE-Elw0IpnMYlncJ4Ow_BI9u-FmIeIvh33lcXr-PHVbmJeUnrNWj2V0HjUiaELH21_hagPJ7eBAjE0ptzYyVeijcs4x8ZFivMTR7ec01UxVTJSpHoassppbzg2zzpK9EqyVUp0iLjrSi2W87zXCihaMc50zoxFaWUpTzdpSUrWL7RUhyYzNssZ2Jb7naQpfoozLCZMje1XzJrsCp5UWTJIA56CGt_W31ZdL72uK9m9R7GLkCWDibE8AslmjjMP4a69rLfZZDv8csqWneK5ihexFSVWbaLYJPRD9U_tUyRJeeKfgYAAP__ErhJ5Q">