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

    <tr>
        <th>Summary</th>
        <td>
            Missed optimization combining saturating-add with min
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          jrose-signal
      </td>
    </tr>
</table>

<pre>
    The following IR (simplified from optimized output of rustc)

```llvm
; min(x.saturating_add(1), 5)
define noundef i32 @test(i32 noundef %x) {
start:
  %0 = tail call i32 @llvm.uadd.sat.i32(i32 %x, i32 1)
  %1 = tail call noundef i32 @llvm.umin.i32(i32 %0, i32 5)
  ret i32 %1
}
```

produces the following assembly

```asm
test:
        incl    %edi
        movl    $-1, %ecx
        cmovnel %edi, %ecx
        cmpl    $5, %ecx
        movl    $5, %eax
        cmovbl  %ecx, %eax
        retq
```

but it could just be

```asm
test:
        cmpl    $5, %edi
        movl    $4, %eax
        cmovbl  %edi, %eax
        incl    %eax
        retq
```

or similar.

(Very similar to #92433, but with a constant as an argument to `min` instead of another addition or variable.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlM-P-jYQxf8a5zICOZOEkEMO3e8KqYdeqqrXyokNzMqxqT1md_vXVw6BhRXqDwmB8Jv58PzIjIqRDs6YXjQvonktVOKjD_1b8NGssqRsMXj92f92NLD31vp3cgf4-VcQuI00nSztyWjYBz-BPzFN9JfR4BOfEoPfQ0iRR4GdkK9C_rS8b-TlZe15Wo6qF5jICdx-rKPiFBSTO_yhtBa4LXM__oDmxtFmT86A88lpsweqEEQt2UQWuM3frorA5kNgB6J9uXRGVoFFtTiBXCBBVK_AiiyMytorLZtbJ6V1NrSmChf0BfljLitvjmZS-Y30zd-FOJF7pMkrrbmjBcOw6OUSUfv6Lb77TE_B6zSaCPzwR6kYzTTYz6fxq7ikPwd3zUTIjtxohewENkbT7XTy58tpvSqz5SyPHzd5nPzZmbu-ZyWnhdA8Ub_4N1U94ocrffx4UhEM__kPCQ2JgRhGn6yGtxQZBvP_Ynli_2k89b_Z_wrnruIu9P9-KR8g0kRWhfXDXXD7uwmfVw3Yg8Cqw7qq8i_nKN6Jj6Bg9C6ycgwqgnKgwiFNxvHcsZF5JDcSyEU2Sud5Vs7z0QRQWhOTd-ADnFUgNVizFtgVuq90V3WqMH3ZYtm2mwY3xbGvat1J1da62Zp2rzUOQzPU1XYc98227LqCepRYyxYrrMoGN2tdadkNZdMNZtA1NqKWZlJk1_Mc-XAoKMZk-lJKbNvCqsHYOC8yRGfeYVYFYt5roc9NqyEdYh5Eihy_MExsTf8LxZhX12WJqflyo58GcnmQvpbSSml9SW8iV6Rg-yPzKeYHBXcCdwfiYxrWo58E7uYNd_lYnYJ_MyML3M3OosDdYv3c498BAAD__-k6lys">