GCC not (optimally) exploiting restrict pointers?

Richard Guenther rguenth@tat.physik.uni-tuebingen.de
Wed Dec 15 12:35:00 GMT 2004


Hi!

This may be a language lawyer question.  Consider:

double foo(double * __restrict__ a, double * RESTRICT b)
{
        *a += b[0];
        *a += b[1];
        *a += b[2];
        *a += b[3];
        return *a;
}

compiling the above with GCC 3.4 or 4.0 with -O2 -DRESTRICT= will
produce

foo:
        pushl   %ebp    #
        movl    %esp, %ebp      #,
        movl    12(%ebp), %eax  # b, b
        movl    8(%ebp), %edx   # a, a
        fldl    (%eax)  #* b
        faddl   (%edx)  #* a
        fstl    (%edx)  #* a
        faddl   8(%eax) #
        fstl    (%edx)  #* a
        faddl   16(%eax)        #
        fstl    (%edx)  #* a
        faddl   24(%eax)        #
        fstl    (%edx)  #* a
        popl    %ebp    #
        ret

with -O2 -DRESTRICT=__restrict__ is gets (obviously)

foo:
        pushl   %ebp    #
        movl    %esp, %ebp      #,
        movl    12(%ebp), %eax  # b, b
        movl    8(%ebp), %edx   # a, a
        fldl    (%eax)  #* b
        faddl   (%edx)  #* a
        faddl   8(%eax) #
        faddl   16(%eax)        #
        faddl   24(%eax)        #
        fstl    (%edx)  #* a
        popl    %ebp    #
        ret


Now, if I read 6.7.3 (7) correct, the second output is correct for the
first case, too.  And in fact, the Intel compiler produces the
optimized output in _both_ cases.

Is GCC right in not doing the optimization in the first case,
or has it just missed the optimization opportunity?

Thanks,
Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/



More information about the Gcc mailing list