GCC's optimizer is able to partially unroll a recursive function. As one might expect, this causes some code duplication. You get several unrolled copies of the code before the recursive call, then the recursive call itself, and then several unrolled copies of the code after the recursive call.
However, when the code following the recursive call is very simple, the multiple copies can be redundant. In a code fragment which I will attach to this report, the code after the recursive call reduces to a single "movl" instruction. There is no need to have eight identical copies of that instruction in sequence. Some sort of (peephole?) optimization pass ought to be able to collapse those down to just a single instruction. exact version of GCC: 4.0.0 system type: i686-pc-linux-gnu; specifically, a Tao Linux 1.0 box options given when GCC was configured/built: ../gcc-4.0.0/configure --prefix=/s/gcc-4.0.0/i386_tao10 --enable-shared --enable-threads --with-pic --enable-languages=all : (reconfigured) ../gcc-4.0.0/configure --prefix=/s/gcc-4.0.0/i386_tao10 --enable-shared --enable-threads --with-pic --enable-languages=all --with-gmp=/s/gmp-4.1.4/ : (reconfigured) ../gcc-4.0.0/configure --prefix=/s/gcc-4.0.0/i386_tao10 --enable-shared --enable-threads --with-pic --with-gmp=/s/gmp-4.1.4/ --enable-languages=c,c++,f95 complete command line that triggers the bug: "gcc -S -O3 redundant.i" compiler output (error messages, warnings, etc.): none preprocessed file (*.i*) that triggers the bug: attached to this report -- Summary: unrolled recursion leaves many redundant instructions Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: liblit at cs dot wisc dot edu CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21558