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

    <tr>
        <th>Summary</th>
        <td>
            Simplify `sadd_overflow`+`assume` to `add nsw` [InstCombine]
        </td>
    </tr>

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

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

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

<pre>
    The probably never comes up in C++, but [in Rust](https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=1e5ca414afeeababc61370cdad34256c) people can easily end up there from things that boil down to
```rust
x.checked_add(y).unwrap_unchecked()
```

Proof: <https://alive2.llvm.org/ce/z/m-n_PG>
```llvm
define i32 @src(i32 noundef %x, i32 noundef %y) noundef {
start:
  %#0 = sadd_overflow i32 noundef %x, noundef %y
  %_7.1 = extractvalue {i32, i1, i24} %#0, 1
  %_10 = xor i1 %_7.1, 1
  %_7.0 = extractvalue {i32, i1, i24} %#0, 0
  assume i1 %_10
  ret i32 %_7.0
}
=>
define i32 @tgt(i32 noundef %x, i32 noundef %y) noundef {
start:
  %r = add nsw i32 noundef %x, noundef %y
  ret i32 %r
}
Transformation seems to be correct!
```

And of course the `uadd_overflow`+`assume` → `add nuw` too.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVMuO6zYM_RpmI4yhhx_xwovJ-Kbo7qK9-4Es0bFaWQokOTPp1xeyM68UaIuigKGEFHXIwyNRxmhODrGD6gBVv5NLmnzoovIpzWreDV5fux8TknPwgxzslTi8YCDKzxjJcibGkSfgh_V7IsOSCFQH48gvS0xQ9cD3U0rnCOIR-BH48WzltQhLTA9WulPhwyn7xfGCIRrvQPTOnKZkr8Dr2WsE0Qe0KCMCr1GbtAVxyhnw-mRiAtEzrJQsWSlHRDnIQdVMNFRpqUXJq1oBb8kZ_dkiUdIRlNHYK0GnM4M0YUAyBj-TNBl3iiRNMpHBG0u0f3EkeaA90Eeo6fbl8jfXa6EmVL-jfpZaA99fgbfF4l6CPD8v7rYHfA-8vcO4mev6PXg_gngkIJ6-dktac0FeWHuZb61SCPz4B_Dj_OCev_8E4tsdcI7dXBpH45AYwQmUNAYFfJ8N5xencSTAq9cs2p0vc_iwm8MGFpMMKde1WiQHAheUgOhJlFo_-wuG0fqXe7g1xRf4D4TnpmArAr6mIFW6SLtgzmkEXytj68pLaPq3jNnDPmOwrYhXH4hhb6h_iWoK-l8y0TcMGeMy41sG9u4PmLYObzluYjT97Y_o3xX6Kkc6pf9ZjrDyk1oTF_-9Cp_qD3fF_wjSxdGHWeZHRyLiHEnyZECifAioEnD2N9f60WniR6L8EiLmZ0agpsvnu5IP8APUdOsu1JTANw77Glqeg1cySw4jyftig93pTuhWtHKHHWtow5hoq2o3dWoUpWCM71VZV3VZ1qIVTUv3bSWbulL1znSc8pJyWtGatawqSja2jdRVqVrdDEJBSXGWxr4_uJ2JccFuT2vR7Kwc0MZ1UnLu8IWsm8B5Hpyhy2cehuUUoaTWxBQ_UJJJFrtfzXy2ZrxmZvEf2pD8O_-48ofq8LOL6cnPg3GYMy7Bdl-nxcmkaRkK5Wfgx3UObD8P5-B_W-U6riVH4MeV0p8BAAD___GEvkc">