1

我想在我的代码中对矩阵向量产品进行向量化。我尝试在 GCC 中使用自动矢量化,但它根本不起作用,我不知道如何使它起作用。现在我尝试一个非常简单的示例代码:

#define N 200000
double a[N] __attribute__(( aligned(16) ));
double b[N] __attribute__(( aligned(16) )) ;
double c[N] __attribute__(( aligned(16) )) ;

void f()
{ 
    int i;

    for( i = 0; i < N; i++ )
    {
        a[i] = b[i] + c[i];
    }
}

int main( int argc,char** argv )
{
    f();

    return( 0 );
}

我使用 gcc 版本 4.9.2 并使用标志编译(为了完整性)

-Wall -O3 -ftree-vectorize -march=native -msse2 -fopt-info-vec-missed -ftree-vectorizer-verbose=1 -std=c++11 -fdiagnostics-color=auto

我得到以下输出(我真的不明白这些东西的含义,但底线显然是矢量化不起作用):

optimization2.cpp:10:2: note: misalign = 0 bytes of ref b[i_11]
optimization2.cpp:10:2: note: misalign = 0 bytes of ref c[i_11]
optimization2.cpp:10:2: note: misalign = 0 bytes of ref a[i_11]
optimization2.cpp:10:2: note: virtual phi. skip.
optimization2.cpp:10:2: note: num. args = 4 (not unary/binary/ternary op).
optimization2.cpp:10:2: note: not ssa-name.
optimization2.cpp:10:2: note: use not simple.
optimization2.cpp:10:2: note: num. args = 4 (not unary/binary/ternary op).
optimization2.cpp:10:2: note: not ssa-name.
optimization2.cpp:10:2: note: use not simple.
optimization2.cpp:6:6: note: not vectorized: not enough data-refs in basic block.
optimization2.cpp:12:13: note: not vectorized: no vectype for stmt: vect__4.6_1 = MEM[(int *)vectp_b.4_9];
 scalar_type: vector(4) int
optimization2.cpp:12:13: note: not vectorized: not enough data-refs in basic block.
optimization2.cpp:6:6: note: not vectorized: not enough data-refs in basic block.
optimization2.cpp:14:1: note: not vectorized: not enough data-refs in basic block.
optimization2.cpp:10:2: note: misalign = 0 bytes of ref b[i_12]
optimization2.cpp:10:2: note: misalign = 0 bytes of ref c[i_12]
optimization2.cpp:10:2: note: misalign = 0 bytes of ref a[i_12]
optimization2.cpp:10:2: note: virtual phi. skip.
optimization2.cpp:10:2: note: num. args = 4 (not unary/binary/ternary op).
optimization2.cpp:10:2: note: not ssa-name.
optimization2.cpp:10:2: note: use not simple.
optimization2.cpp:10:2: note: num. args = 4 (not unary/binary/ternary op).
optimization2.cpp:10:2: note: not ssa-name.
optimization2.cpp:10:2: note: use not simple.
optimization2.cpp:16:5: note: not vectorized: not enough data-refs in basic block.
optimization2.cpp:12:13: note: not vectorized: no vectype for stmt: vect__4.28_2 = MEM[(int *)vectp_b.26_9];
 scalar_type: vector(4) int
optimization2.cpp:12:13: note: not vectorized: not enough data-refs in basic block.
optimization2.cpp:16:5: note: not vectorized: not enough data-refs in basic block.
optimization2.cpp:16:5: note: not vectorized: not enough data-refs in basic block.

我尝试了许多其他的东西和其他代码,但从来没有得到任何矢量化的东西。诀窍是什么?

4

0 回答 0