https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98932
Bug ID: 98932
Summary: Wrong output with -O3 on aarch64
Product: gcc
Version: 8.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: kristian.klausen at scoutdi dot com
Target Milestone: ---
Hi,
I have been struggling with a vectorization issue, and have managed to
re-create to a minimal example as attached.
When compiled with `-O2` the correct output is produced, however when compiled
with `-O3` the output is bogus when compiled with gcc-8 and gcc-9. Gcc-7 gives
the correct output.
Tested with the following versions under qemu for aarch64:
```
g++-7 --version
g++-7 (Ubuntu/Linaro 7.5.0-6ubuntu2) 7.5.0
g++-8 --version
g++-8 (Ubuntu/Linaro 8.4.0-3ubuntu2) 8.4.0
g++-9 --version
g++-9 (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
```
Output:
```
:~# g++-9 -O3 a.cpp && ./a.out
Length is: 26348240
:~# g++-8 -O3 a.cpp && ./a.out
Length is: 26348240
:~# g++-7 -O3 a.cpp && ./a.out
Length is: 294
```
Also gave it a go with the suggested flags before filing the report:
```
g++-8 -O3 -Wall -Wextra -fno-strict-aliasing -fwrapv a.cpp && ./a.out
Length is: 26348240
```
The code gives the correct output with gcc-10:
```
g++-10 -O3 a.cpp && ./a.out
Length is: 294
g++-10 --version
g++-10 (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
```
Let me know if I can provide more information.
Best,
Kristian