This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/15242] pessimization of "goto *"
- From: "zlomj9am at artax dot karlin dot mff dot cuni dot cz" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jul 2004 07:01:37 -0000
- Subject: [Bug rtl-optimization/15242] pessimization of "goto *"
- References: <20040501142654.15242.anton@mips.complang.tuwien.ac.at>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From zlomj9am at artax dot karlin dot mff dot cuni dot cz 2004-07-16 07:01 -------
Subject: Re: pessimization of "goto *"
> > The optimization is enabled at -O2
> Not as far as I can tell (tried it on i386 with patched versions of
> gcc-3.5-20040704 and gcc-3.5-20040523).
Yes, it is enabled by the patch. The patch duplicates block with computed goto
to place where a uncond jump to the conputed goto block is if the block is
small enough.
The computed jump in the small testcase is not duplicated, because the uncond
jumps from other places do not jump to a basic block which contains the
computed jump but to other block:
f:
pushl %ebp
movl %esp, %ebp
pushl %ebx
movl 8(%ebp), %ebx
.p2align 2,,3
.L37:
cmpl $4, %ebx
jle .L39
.L34:
movl $5, %ebx
.L9:
movl a.1118(,%ebx,4), %eax
jmp *%eax
.p2align 2,,3
.L39:
testl %ebx, %ebx
jg .L9
jmp .L34
.p2align 2,,3
.L3:
popl %ebx
leave
ret
.p2align 2,,3
.L2:
sall %ebx
jmp .L37
.p2align 2,,3
.L1:
addl $2, %ebx
jmp .L37
.p2align 2,,3
.L5:
decl %ebx
jmp .L37
.p2align 2,,3
.L4:
incl %ebx
jmp .L37
However, I see that after the L39 there is a cond jump to the computed jump block.
This is not handled by my patch but could be.
> We would like to use -fno-reorder-blocks with
> duplicate_computed_gotos, either through an extra option, or by just
> having duplicate_computed_gotos all the time (at least for our code
> these gotos were duplicated already in the source code, so duplicating
> them again in the back end is closer to the idea of
> -fno-reorder-blocks than not duplicating them).
Adding an new flag is possible. However, I do not see why you explicitelly want
to disable reorder-blocks.
> One other thing I noticed is that apparently there is no combining
> pass (or its tree-ssa equivalent) after duplicate_computed_gotos,
> resulting in compiling code like
>
> goto *a[i];
>
> into
>
> movl a.0(,%ebx,4), %eax
> jmp *%eax
>
> instead of
>
> jmp *a.0(,%ebx,4)
The combiner should have already combined these insns before the duplication of
computed gotos is run. This pass just duplicates some insns.
Josef
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15242