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

    <tr>
        <th>Summary</th>
        <td>
            Miscompilation with noalias and pointer equality
        </td>
    </tr>

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

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

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

<pre>
    Reproducer
```c
// test.c
#include <stdio.h>

int x;

__attribute__((noinline))
int test(int * restrict ptr) {
    *ptr = 1;
    if (ptr == &x) {
        *ptr = 2;
    }
    return *ptr;
}

int main() {
 printf("%d\n", test(&x));
}
```
```
$ clang -O3  test.c
$ ./a.out
1
```
Tested with clang 15.0.0 and trunk

The issue appears to be that Clang's constant propagation replaces `*ptr = 2` with `x = 2`, which breaks the noalias *based on* analysis and allows the `return *ptr` to be simplified to `return 1`.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU8uuozgQ_ZpiU7rImADJgkX3zWQ3GmnU-6iASvC0YzN2Mbn370cm5NEPyQK7HqdOnbIpRnN2zC1UX6HaZzTL6EPbU-i8kDPzhVzW-eGz_Zun4Ie55wBqD-oL1Oq2-vWsD6APKBwlf5hK43o7D4xQvkcZjM9HKP9YvcvXOMEPKL--2o5HEgmmm4WPR9Bb0FvnjbPGMehdWo_UVA70Nm1Bf8HAUYLpBScJoHcIzQqMiClgkoBQ7rF4VEwOc0LQ29WX3KDrj1_Sf4LQP0BAs38eAssc3Br87O0e8mR_IeOW_l5LTcE4OS1mDboaoHp3y_b93u1KL61fwe9j-f1Rb7C35M749leJPw1rgznoA-V-lpup-C3GN47CA16NjCtWUeUqV0huQAmz-_7a5reR0cQ4M9I0MYWI4rFjlJEE31M66CZi710UcoJT8BOdSYx3GHiy1HPEVPtV-VrdykOtPh6mJNB1NP2IXWD6HlFGRufJGoppFh1FHtC7dE_Ikf2MJi6cyVp_vYVDrX4cXq1WvtFcJmtOhodkeMYVUKv81mo2tOWwK3eUcVvUTbEtNrrcZGPbq0L3NdXMVd1xwwNVPZXFtiRVUkFdZlqttC60Lou6UuUm10196k6qY6qKU9Vo2Ci-kLG5tf9dch_O2aJpW-3qZpdZ6tjG5Qlr7fh6EzzdmWqfhTblvHXzOcJGWRMlPlHEiOX2TxN7f5mMvcm-SHsXLgk0eeOEA_K_M1kjn9kcbDuKTBHK9d2fjYxzl_f-AvqQ4Nff2xT8P9wL6MNCKoI-LKT_DwAA__-r-ExC">