简体   繁体   中英

g++ autovectorization fail for the most basic example

I am currently trying to use autovectorization with g++. To do so, I use the following minimal example:

#include <array>
int main()
{
    std::array<double, 16> x;
    for (unsigned int i = 0; i < 16; i++) x[i] = i;
    return x[15];
}

And I compile with:

g++-4.7 -Wall -Wextra -std=c++11 -O3 -ftree-vectorizer-verbose=9 tests.cpp -o tests

And the result is:

Analyzing loop at tests.cpp:5

5: ===== analyze_loop_nest =====
5: === vect_analyze_loop_form ===
5: === get_loop_niters ===
5: ==> get_loop_niters:16
5: === vect_analyze_data_refs ===

5: not vectorized: no vectype for stmt: MEM[(value_type &)&x]._M_instance[i_21] = D.21296_5;
 scalar_type: value_type
5: bad data references.
tests.cpp:2: note: vectorized 0 loops in function.

What is the problem and how to solve it ?

EDIT: and the result is the same for:

#include <array>
int main()
{
    std::array<int, 16> x;
    for (int i = 0; i < 16; i++) x[i] = i;
    return x[15];
}

Check your compile flags no vectype for stmt means that your architecture doesn't support these instructions.

Set -march=native or -march=corei7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM