https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71785

--- Comment #19 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Aleksey from comment #16)
> > > It would be helpful if you give the explanation how these options affect
> > > "un-factoring".
> > 
> > What options?  -fno-reorder-blocks?  Those doo the same to this code as
> > they do anywhere else: the compiler does not run the reorder-blocks
> > pass, so you get worse code.
> 
> This is not an explanation.

Of course it is.  If you want a motivation instead, then a good argument is
that this is consistent with how all other options are handled.

'-freorder-blocks'
     Reorder basic blocks in the compiled function in order to reduce
     number of taken branches and improve code locality.

     Enabled at levels '-O', '-O2', '-O3', '-Os'.

If you disable this option, you get more taken branches and a less linear
control flow.  As documented.

And not just for duplicating the computed gotos, but in *many* other places.
You *need* to have this pass enabled, to get good code.  And almost everyone
always has; this works both ways.

> START - the very first "goto *xxx" - was not optimized, since "bb 5" has
> only 1 predecessor.
> But it's optimized in later step "bbro". That's exactly why option
> "-fno-reorder-blocks" breaks first jump optimization.
> 
> Can someone explain why there are such conditions:
>       if (single_pred_p (bb))
>           return false;
> 
>       if (single_pred_p (bb))
>           continue;
> in maybe_duplicate_computed_goto function?

It duplicates the code, one copy for every predecessor to jump to.  It does
not move existing blocks elsewhere.

> One can ask compiler to not reorder
> them with option "-fno-reorder-blocks" - that's enough to fulfil the
> requirements. This option was used in 2004 in QEMU for similar purposes.

It is 15 years later now.  If you want a compiler that behaves like GCC did
in 2004, you should use a GCC release from 2004 perhaps?

> So GCC has enough options to structure the machine code in C (and C++)
> language in desired way, there is no need to go into assembler.

That is not how things work.

Reply via email to