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

    <tr>
        <th>Summary</th>
        <td>
            [FunctionAttrs] Incorrect nonnull inference for non-inbounds GEP
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            miscompilation,
            llvm:optimizations
      </td>
    </tr>

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

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

<pre>
    FunctionAttrs incorrectly infers that the following function returns nonnull (https://llvm.godbolt.org/z/49Kbq15xn):
```llvm
define ptr @test(ptr nonnull %arg) {
  %res = getelementptr i8, ptr %arg, i64 -8
  ret ptr %res
}
```
This is because the code assumes that the result of a GEP is non-null if the source is non-null here: https://github.com/llvm/llvm-project/blob/d98a78590f4f9e43fdfb69fde7d154a985e4560f/llvm/lib/Transforms/IPO/FunctionAttrs.cpp#L1189 This is not correct for non-inbounds GEPs.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUU11v3CoQ_TX4Be0Kg7948MMme30V3Ss1D_kDYA82LYYtg9smv76y19tkq75UsmQxwxnmnJmjEO3oAVpSPhDOvf1ie8I5Kc-ZWtIUYruFMh2G17ZbfJ9s8KeUIlLr-xAj9Mm9UusNRKRpUommCagJzoXv1o_U7BgaIS3RI_XB-8U5SngzpXRBIk6Ed4R3zn2bj2MYdHDpGOJIePdGeFfI__TXvPzhCZfrXXYm7EQqdv1W0DU0gLEe6CVFSgqWABPhzXp6f7BUa1VJSf1wxdA1GAEpEWc6QgIHM_i0omxD-OO12o57pLYq6KG5QSOkWz4C7n3V598avB5fJovUItXQqwVh06gPA1CFuMzwQbkIuLhEg6GK_vvP8wrywR82BtZsVzAssYe7zAQRiDjRe0VHm6ZFH_sw7_Luv8Mlhs_QJ8I77YImvBtko-qmlMwURkIhzGB0Jc0A9ZCXhZJNCUVZMfOhjl1xL1F5NCHOSHj39PyJ8O5uSY795UK4-D_PG0lvIviQ6L461IRtQAfrdVj8gCtnPGZDKwYppMqgzeu8kE1dlTKbWlFUKi-U0IPsTZULU1eyBNk3Qy2aXLDMtpzxgpWsYpLXQh41q0StOWtkozRUnBQMZmXdcVu3EMfMIi7Qyjyv68wpDQ53M8wW-zBfrFMrn9UV_JFwvgkgTuGS7GzfthzulontJq9eRiQFcxYTvr-TbHKbz-4UIuWZPt2c9GtXNz-B7-GPAmVLdO1fj3rjuc5po_ozAAD__4K-RmY">