我要评分
获取效率
正确性
完整性
易理解

-falias-analysis-expand-ssa

Description

Enhanced alias analysis capabilities can effectively identify and eliminate false data dependencies of adjacent array element accesses outside of loop bodies, enabling the safe vectorization of continuous operations on adjacent elements and improving code execution efficiency.

Usage

Enable the -O2 or higher optimization level and enable the compilation option -falias-analysis-expand-ssa.

Result

The test case is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void f(double *p, long i)
{
    p[i+0] += 1;
    p[i+1] += 1;
}
void g(double *p, long i)
{
    double *q = p + i;
    q[0] += 1;
    q[1] += 1;
}

Test command:

1
gcc -O2  -fdump-tree-slp-details -falias-analysis-expand-ssa test.c -S -o test.s
Figure 1 Option disabled

Figure 2 Option enabled

When the option is not enabled, for function f, the compiler considers p[i+0] and p[i+1] as aliases of each other, resulting in a dependency, and vectorization fails. When the option is enabled, vectorization succeeds.