| Issue |
240818
|
| Summary |
[Flang] [AArch64] Incorrect TBAA tags for dummy arguments cause miscompile with LTO and SVE
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
itou-fj
|
## Summary
Flang produces an incorrect result for the Fortran program linked below on AArch64 with SVE when it is compiled with LTO and a fixed 256-bit vector length.
The program is expected to print only `pass`, but the compiled executable prints `NG` followed by `pass`. The issue reproduces consistently and is still present on current `main`.
## Reproducer
The reproducer is the following Fujitsu Compiler Test Suite program: [`Fortran/0726/0726_0205.f90`](https://github.com/fujitsu/compiler-test-suite/blob/main/Fortran/0726/0726_0205.f90). The incorrect result is detected by the check at [line 54](https://github.com/fujitsu/compiler-test-suite/blob/main/Fortran/0726/0726_0205.f90#L54).
Build and run on AArch64 with SVE:
```bash
FLANG=/path/to/flang
LLVM_BIN=/path/to/llvm/bin
$FLANG -O3 -ffast-math -flto -fuse-ld=lld -B"$LLVM_BIN" -march=armv8.4-a+sve -DNDEBUG -msve-vector-bits=256 0726_0205.f90
```
Expected output:
```text
pass
```
Actual output:
```text
NG
pass
```
## Conditions observed
The failure reproduces with:
- `-O3 -ffast-math -flto`
- `-msve-vector-bits=256`
The failure does not reproduce in the tested configuration when:
- LTO is removed;
- `-fno-slp-vectorize` is added;
- `-mllvm -disable-fir-alias-tags` is added;
- `-mllvm -force-no-alias=false` is added;
- both compile-time and runtime SVE VL are changed to 128 bits.
## Versions tested
The first commit where the failure was observed is:
[`66c907087dd0db2ea8bc9987337af1b895d77808`](https://github.com/llvm/llvm-project/commit/66c907087dd0db2ea8bc9987337af1b895d77808):
The parent passes and this commit fails under otherwise identical conditions. However, this does not establish that the commit introduced the underlying bug. The commit changes the AArch64 cost model and appears to expose a pre-existing issue in the alias information emitted by Flang.
Comparison under identical conditions:
| Revision | Result |
| --- | --- |
| Parent `869efece5040e0a0232a42d58c12195d78bac323` | PASS (5/5) |
| `66c907087dd0db2ea8bc9987337af1b895d77808` | NG (5/5) |
It also reproduces on LLVM `main` as of November 5, 2026:
```text
7907a622d07ac3df366c14f794cdfd689414d7bc
```
Result: `NG` in 5/5 runs.
## Root-cause analysis
The analysis below includes AI-assisted investigation and should be independently reviewed by whoever investigates or fixes this issue.
The relevant stores in LTO pre-codegen IR have different TBAA tags:
```llvm
store <8 x i32> ..., ptr %4, align 64, !tbaa !116
store <8 x i32> ..., ptr %5, align 64, !tbaa !79
```
Their metadata is:
```llvm
!79 = !{!80, !80, i64 0}
!80 = !{!"dummy arg data/_QFs1FssEi2", !81, i64 0}
!116 = !{!117, !117, i64 0}
!117 = !{!"dummy arg data/_QFs1FssEi1", !81, i64 0}
```
`i1` and `i2` are different dummy arguments of the same elemental subroutine. However, the same allocation (`jj1`) is passed through `i2` in one call and through `i1` in a later call. Therefore, accesses tagged as `_QFs1FssEi1` and `_QFs1FssEi2` can alias across call sites.
The sibling TBAA nodes cause LLVM to treat these accesses as non-aliasing.
`opt-bisect` identifies the first failing pass as:
```text
pass 157: postmisched
```
Before `postmisched`, the old vector store precedes the scalar stores from the
later call. After `postmisched`, some newer scalar stores are moved before the
old vector store. The old vector store then overwrites those newer values.
Using the same pre-codegen IR:
| Metadata change | Result |
| --- | --- |
| Original metadata | NG |
| Remove only TBAA metadata | PASS |
| Remove only `alias.scope` | NG |
| Remove only `noalias` | NG |
| Remove all alias-analysis metadata | PASS |
This indicates that the problematic information is the dummy-argument TBAA metadata emitted by Flang. Commit `66c9070` appears to expose the pre-existing metadata issue through a changed optimization/code-generation shape, rather than being the origin of the invalid alias information.
## Environment
- Original failure: AWS Graviton3
- Reproduction host: Fujitsu FX700 (A64FX)
- OS: Rocky Linux 8
- The FX700 process default SVE VL is 512 bits. The reproducer was run with `PR_SVE_SET_VL` to explicitly set the runtime VL to 256 bits, matching `-msve-vector-bits=256`.
- LLVM build: Release, assertions enabled
- Projects: `clang;flang;lld`
- Target: `AArch64`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs