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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Crash on valid input when narrowing type but not updating `range` attribute
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            crash-on-valid
      </td>
    </tr>

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

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

<pre>
    https://godbolt.org/z/b3M1dj6aj

```
define void @SetRow_C(ptr %p, i32 %conv) {
entry:
  %call.i = tail call ptr @__memset_chk(ptr %p, i32 range(i32 0, 123) %conv, i64 1, i64 1)
  ret void
}

declare ptr @__memset_chk(ptr, i32, i64, i64)
```

We keep the `range(i32 ...)` when we replace the `_chk` with `memset.inline.p0.i64` which leads to a crash:
```
Range bit width must match type bit width!
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %p, i8 range(i32 0, 250) %0, i64 1, i1 false)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE2P4ygQ_TX4UmrLLn8kOfjQkyjSHvYye9hjC0PZpoeABeVEvb9-heN0Z2dmpchQUB-v3qMiYzSjI-pE800gjt7qyGScE4iiOWVy4cmH7us8673-6CbmOYrqVeBZ4Hn0uveWcx9Gged_BJ776s9Sv7fyXRQnUbxu37bYfqupaTCO4OqNBlEXfxF_97e3o8D9zAEENrPAI5gK0155dxV4ALH7do8mx-EjIVgtWH2ktbkBUZ2ApbGQbFhz1cXb24UukfhNTT9-UyFIN5LAfdoX6bDEai33qHwE09ZQPm0Oj8qBeG1ia3J3eu5Zk7Iy0P_D2BBsiT-Xw28pu3__JvhBNANPBKItnrHneZ5i2wJuEzm4EQSarVT0cF4Lp2vDU7LvcHLjrHGUz0Weqq_hRk1gSeoI7EGCCjJOn3z_hOt7ggC9YbgZzRNclshwkawm4I_56UZg-aDtS6LHC7D2esk3QBuSu1LOL07TAM47t1gL0prRQQmaAg0UyCmSvU0clJtod2H3v-qKTbG5FP8VtYRB2ki_Mp_prtKH6iAz6sodHkosy0OdTV0vB5S73UBNrQZV7fZ7qXs5qLaXbSsblZkOC6zLomyxwraq87aiQe52e1U3h0bSXtQFXaSx-dq5D2NmYlyoK0tsqyqzsicbt8lMLqJ6NS6y8pfeOEoTikeBuErz4t3LVVqjt8ENXYp46ZcxJmpN5PhVhg3bdeT_cJGPW7rmBMeUCbyDNRMYNy98f0lOhuBvxo2boAuD8wzLrCWn08932BYgmYPpF6ZsCfbnvwrD09Lnyl8Entee7svLHPw7KRZ4XjmIAs8bDdcO_w0AAP__JydkCg">