This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: g++ doesn't unroll a loop it should unroll
- From: Ian Lance Taylor <iant at google dot com>
- To: BenoÃt Jacob <jacob at math dot jussieu dot fr>
- Cc: gcc at gcc dot gnu dot org
- Date: 13 Dec 2006 07:46:19 -0800
- Subject: Re: g++ doesn't unroll a loop it should unroll
- References: <200612131244.58528.jacob@math.jussieu.fr>
BenoÃt Jacob <jacob@math.jussieu.fr> writes:
> I'm developing a Free C++ template library (1) in which it is very important
> that certain loops get unrolled, but at the same time I can't unroll them by
> hand, because they depend on template parameters.
>
> My problem is that G++ 4.1.1 (Gentoo) doesn't unroll these loops.
>
> I have written a standalone simple program showing this problem; I attach it
> (toto.cpp) and I also paste it below. This program does a loop if UNROLL is
> not defined, and does the same thing but with the loop unrolled by hand if
> UNROLL is defined. So one would expect that with g++ -O3, the speed would be
> the same in both cases. Alas, it's not:
When I try it, gcc does unroll the loops. It completely unrolls the
inner loop, but only partially unrolls the outer loop. The reason it
doesn't completely unroll the outer loop is simply that gcc doesn't
attempt to completely unroll loops which contain inner loops.
This could probably be fixed: we could probably completely unroll a
loop if all its inner loop were completely unrolled. I encourage you
to file a bug report. See http://gcc.gnu.org/bugs.html.
Ian