https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90304
Bug ID: 90304
Summary: -O3 vectorization gets worse when code is moved into
main()
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: john.boyer at tutanota dot com
Target Milestone: ---
The following code will get much better assembly if it is not in main():
for (int i = 0; i < 1024; ++i)
result[i] = first[i] * second[i];
It simply multiplies two integers and stores the result.
When this code is moved into main(), it appears part of the loop no longer gets
vectorized and uses imul instead.
This does not happen when the loop is moved to it's own function.
The two left panes contain the assembly of both versions of this code:
https://godbolt.org/z/pNdbE5
NOTE: the noinline attribute has no effect on this issue, it is simply to make
the assembly more readable.