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

    <tr>
        <th>Summary</th>
        <td>
            `assume`ing the result isn't setting the `nsw` flag on `add`
        </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>
    Original Rust example: <https://rust.godbolt.org/z/xze3vEx8E>
```rust
pub unsafe fn extend_packed_unchecked(a: Layout, b: Layout) -> usize {
 a.extend_packed(b).unwrap_unchecked().size()
}
```

Actual output (-) and what I'd like to get instead (+):
```diff
 define noundef i64 @extend_packed_unchecked(i64 noundef range(i64 1, -9223372036854775807) %0, i64 noundef %1, i64 noundef range(i64 1, -9223372036854775807) %b.0, i64 noundef %b.1) unnamed_addr {
 start:
-  %new_size = add nuw i64 %b.1, %1
+ %new_size = add nuw nsw i64 %b.1, %1
   %_11 = sub nuw i64 -9223372036854775808, %0
   %_10 = icmp ule i64 %new_size, %_11
   tail call void @llvm.assume(i1 %_10)
   ret i64 %new_size
 }
```

Note that `%_11 sgt -1`, thanks to the range attribute on the `%0` parameter.

Alive proof that this is allowed: <https://alive2.llvm.org/ce/z/Dn2P8R>
Repro that more `opt` on trunk doesn't do it: <https://llvm.godbolt.org/z/Kr8n37s41>

---

Oh, turns out the simpler case of just 
```llvm
define noundef i64 @demo_b(i64 noundef %1, i64 noundef %b.1) unnamed_addr {
start:
  %new_size = add nuw i64 %b.1, %1
 %_10 = icmp ule i64 %new_size, 9223372036854775807
  tail call void @llvm.assume(i1 %_10)
  ret i64 %new_size
}
```
doesn't add the `nsw` either.

And that'd be allowed too: <https://alive2.llvm.org/ce/z/PeC7No>

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVdtu2zgQ_Rr6ZWCBoqyLH_Sg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