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

    <tr>
        <th>Summary</th>
        <td>
            [LoopVectorize] Diff check is not emitted correctly in nested loop
        </td>
    </tr>

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

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

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

<pre>
    Consider following nested loop

```c
void subtract_arrays(unsigned int *a, unsigned int *b, int len) {
    int i, j;
    for(j = 0; j < len; j++) {
        for(i = 0; i < len; i++) {
            a[j] = a[j] - b[i];
        }
    }
}
```

Generated code will produce incorrect result if loop vectorizer is enabled and arrays a and b overlap.
The reason is that LLVM does not emit runtime check for the nested loop and always executes vectorized version of a loop.
This happens because read access for array ‘a’ is moved by LICM outside of the nested loop to a parent loop and is therefore not seen by loop analysis.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9U02TmzAM_TXmotkMmEDCgcNu0u10Jnvr7LVjQARnHZuxTdL011d2PptDGYdIsvXekywa053qldFOdmihN0qZo9Rb0Og8dqCMGVm6Zunr5V2m59We_YORHbip8Va0_pewVpwc48uJ8Laa8qX2wPirYHwFz8EmBIOtUDNeAVu8nUGBnhCX4cCO5Q_h3liC3wHL15DSDgRzFRGCw_hbXE9g90x5z5SPmfI_meERrHjbsWId02_OCzRkSjL_ERketljfAzfnblz7-Njc76jRitD21nQIR6kUjNZ0U4vUj9ZYi60Hi25S1Jw-Xg4cKGas_EO3Jx2gFo0iAKHpF28DRHQaMAe0SoyzM9fPAQlJOKNDmh-Eh83m8wM6gw608YB7SVyT9nKP0A7YfoUW0kl8nI0zkToGIvyN7eQp_SapI9M6SRymJx0h4UZPrIMYR9QOGmzF5KIeAmtbdC5yxQKAfeNsmbJqKa5WFSTvqR4q6wSbH6sPMJMPExx4nhV6Q9SjsBgm7So51owWiQZjuQ5RB7TLCaFOTrqL2ATrrCwzviirNEu6Ou-qvBKJl15hTQOwoZzPa81hLtay7y89k_duni82XqI60YU-qkwmq-rB-9Gx_JXxd1pb6YepmbVmT45Sh-vfC43EjjDIlc5NSN_be7HIsyIZ6rypir5fVpiJIsvSUiwK0toJxKbjGZaJEg0qF0QzzjUeIUKQTbITWfOU83TJ82wxX_JsViznfN4KTLuyyYrFnM1T3AupZkHHzNhtYusoqZm2jjaVdN7dN4WLH3zsUcAXkx-Mrb_GDg9JJK6j8L-VqWWj">