[RFC] GCC vectorizer misses an opportunity to hoist loop invariant load after loop versioning.

Cong Hou congh@google.com
Wed Sep 18 20:23:00 GMT 2013


First, look as the code below.


void foo(int* a, int* b, int n) {
    int i;
    for (i = 0; i < n; ++i)
        a[i] = *b;
}


This loop contains possible aliasing between a[i] and *b, and in order
to vectorize this loop, GCC produces two versions of the loop, and
only vectorizes the one in which there is no aliasing between a[i] and
*b. In this version we can assert *b is a loop variant and thereby can
hoist the load and shuffle operations outside of the loop. But the
current implementation does not do this.

If we replace *b by a stack variable then during the vectorization
pass the load and shuffle are already hoisted. So I think we can just
do it during the vectorization pass without passing additional
information to other passes (e.g. pass_lim). Is it safe for us to
assume that there is no aliasing between a variable accessed via an
address which is a loop invariant and any other variable modified in
the loop (the version to be vectorized)?


thanks,
Cong



More information about the Gcc mailing list