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

    <tr>
        <th>Summary</th>
        <td>
            [X86] `sub`+`cmp`+`jmp` could be combined into `sub`+`jmp`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:X86,
            llvm:codegen,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    ```c++
void work(int);

void test(int g)
{
    g -= 3;
    if (g < 0) [[unlikely]]
        return;
    work(g);
}
```
produces
```asm
test(int):
        cmp     edi, 3
        jl      .LBB0_1
        add     edi, -3
        jmp     work(int)
.LBB0_1:
        ret
```
but the better would be (as done by GCC)
```asm
test(int):
        sub     edi, 3
        js      .L1
        jmp     work(int)
.L1:
        ret
```

https://godbolt.org/z/Knhn3jP8n
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVU8uOmzAU_RqzsRIZkxhYsMhD6aJddNldZeMbcMbgCJupZr6-15DHJBpVHXTBj3MfPscX5fRbRQSbrSZ8G43tCdu8OqPpHze8EF6YPhBekuwCfXAI4MPsQJvoMuP5xZHi09AFyfY0u0XHTXOkGNVQku0owzhK1lu0sbfmBewbWe-j3dzjM0AYh_4hy-V0zcPZ8kvcjdW8PA9OjzX4J1D6bt65E5mybR6L1915GkEbwndI5gE92Xlc_thu2e_0EZRafwxdPMdeMj8qPblc0z0fBpX4lKIaAw0tUAUhwIAZR6txEZWWnmrXI_RGv-1294v6ogx-VP-SwV9lSL_A8f_5zd82hLOPMfyA1jitnA1LN2AXHN7x_d63fXb6WfQJVKkQomCrLGWJrjJdZqVMggkWKmy2X4XAJqOYHmnFItj5-A9059v8NM1pfRWydp0yPWiKDNxz4OycjIOtno5oQjuqJQbjwtrX67DAljxBjVocjPcjtiY_rAuRiaStMuBKrXJ2LBgDuWJlvi6ZEEeQUHOerxIrFVgfaRDOlaxfoNdYMXLiPN4NDlOtbFM7DQ309_0Oy4FeuHMwnXmXwbgJXO8TU3HGecq4SPM0XbOlEGVRqlLwoxCQpzlZMeikscuYO4qeDNXERY2NR9AaH_wdlN6bpodJ7phfjqF1Q1W3R-lDMrGuJsp_AaEWNBE">