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

    <tr>
        <th>Summary</th>
        <td>
            aarch64 specific misscompilation with TBAA
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64
      </td>
    </tr>

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

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

<pre>
    This issue relates to https://github.com/llvm/llvm-project/pull/139682, which had to be reverted due to a misscompilation which was only reproducible on aarch64. That patch causes flang to emit more specific TBAA information about local variables. The pull request passed a large number of other tests on aarch64.

The misscompilation is for https://github.com/fujitsu/compiler-test-suite/blob/main/Fortran/0614/0614_0005.f. Without the patch, that program outputs
```
*** ok ***
```

With the patch (and `-O2` or above) the program emits
```
*** ng ***
3 5 7 9 11 13 15 17 19 10 13 14 15 16 17 18 19 20 11 11
```

It can be built using `flang 0614_0005.f -O3`. Alternately, here is the generated LLVMIR:
[llvm-ir.txt](https://github.com/user-attachments/files/20503379/llvm-ir.txt) (in .txt because github doesn't allow .ll).

`flang bug.ll -O3 -o /tmp/out` (flang has to be used so that the correct runtime libraries are linked).

This is reproducible with [the original patch](https://github.com/llvm/llvm-project/commit/cf16c97bfa1416672d8990862369e86f360aa11e) and with that patch cherry-picked onto current main (6602bfa721889).

I don't see any change to the LLVM IR produced by `opt -O3` with and without this patch (other than the changes to the tbaa tags) and this does not reproduce on X86, and so I think this could be an aarch64-specific misscompilation rather than a flang bug.

CC: @DominikAdamski 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVVGP2zYM_jXKC5FAkmPHfsiDr0WAAzoUKIptbwNt07YaWcok-W737wfavkvbrR0GGJAlUB_Jjx8pjNEMjugs8geRv9_hnEYfzqmxOO4a372cP48mgolxJghkMVGE5GFM6RZFVgt9EfoymDTOzaH1k9AXa59el_0t-C_UJqEvt9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