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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] `umax(X, C) + -C` -> `usub.sat(X, C)`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    Alive2: https://alive2.llvm.org/ce/z/oSWe5S
```
define i8 @src(i8 %a) {
  %1 = call i8 @llvm.umax.i8(i8 %a, i8 10)
  %sel = add i8 %1, -10
  ret i8 %sel
}

define i8 @tgt(i8 %a) {
  %res = call i8 @llvm.usub.sat.i8(i8 %a, i8 10)
  ret i8 %res
}

define i8 @src2(i8 %a, i8 %c) {
  %1 = call i8 @llvm.umax.i8(i8 %a, i8 %c)
  %negc = sub i8 0, %c
  %sel = add i8 %1, %negc
  ret i8 %sel
}

define i8 @tgt2(i8 %a, i8 %c) {
  %res = call i8 @llvm.usub.sat.i8(i8 %a, i8 %c)
  ret i8 %res
}
```
Reported by https://github.com/dtcxzyw/llvm-mutation-based-fuzz-service/issues/5.
Related patch: https://github.com/llvm/llvm-project/pull/116888.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE1vnDAQ_TXDBYHs4WPNgQPZLVKvzaG9GpjddWVgZZttsr--skuSbdKNmlZCCOw382aen0daqw4TUQ3FHSAOrn-4PP4ARCh2kVzccTb1uhh18_BYN1qdCSFr4qNzJwtZA9gCtjKsp1qfx3Q2B8C2J8D2AtjO91-puAfWQMnWhzUD7dVEsRIx5MyaHlD4bywkYBXD5g5YE_t_HkO2i3up9QoOFMsoH1IlrqO2fp8zwOop1JIOwXIY4l8w7mEJZwFhyK3LlrQvb7Pz71e1uYO7WZsh--fq7NKlVrr3K3zhN2Rv8lvT45skgEX_XzqtCZ6CJzr0Id4und9mHhYw70u5hn5Mzr9q51-kvW7qhrhXDvxCp9k4GuLu8ZWXD8odly7t5xGwfb4SredPxsVJp-Yp6aSlIdkvl0tiyZxVsLuydiEL2BZpYNDSE5yk649vr8xvND75E8fJzN-pd4DtadEasOW8FEL4lNFQZ0OVVTKimm8yrHLBsYqOdc5Ez-Wm2vB8L7uSY15wRMk7zqjM2BCpGhnmnGeMlSjyKs2yvGKi2gwyp73oEHJGo1T6-Q5HoZuac8GLItKyI23XORGqzRo1WdfPY6cm8iMDt4A4KuuFmU9OjeoStFrHialDd91ysP40lXX2hcspp8MU-jxZt11zFrsYSuY9DCi--VPeBpvgXZxsoWRxAtmnAFldcQ2DkkWL0fWHRX8-xLXzc40_AwAA__8sPnQ2">