On Fri, Oct 6, 2023 at 6:49 PM Jakub Svojgr via Gcc <gcc@gcc.gnu.org> wrote:

> Hello,
> this is an extremely specific scenario - however while compiling
> computer-generated code for a fibonnacci function which looks like this:
>
> I32 GF_fib_I_I(I32 L_0_0)
> {
>     I32 L_2_0; I32 L_5_0; I32 L_6_0;
> bb0:;
>     bool L_0_1 = ((I32)L_0_0) == ((I32)0);
>     if (L_0_1)
>     {
>         goto bb1;
>     }
>     L_2_0 = L_0_0;
>     goto bb2;
> bb1:;
>     return ((I32)1);
> bb2:;
>     bool L_2_1 = ((I32)L_2_0) == ((I32)(0));
>     if (L_2_1)
>     {
>         goto bb4;
>     }
>     L_5_0 = L_2_0;
>     goto bb5;
> bb4:;
>     return ((I32)1);
> bb5:;
>     I32 L_5_1 = ((I32)L_5_0) - ((I32)1);
>     I32 L_5_2 = GF_fib_I_I(L_5_1);
>     I32 L_5_3 = ((I32)L_5_0) - ((I32)2);
>     I32 L_5_4 = GF_fib_I_I(L_5_3);
>     I32 L_5_5 = ((I32)L_5_2) + ((I32)L_5_4);
>     return L_5_5;
> }
>
> Now, when compiling this with x86-64 gcc version 13.2 on GodBolt (
> https://godbolt.org/z/5sj7hPchs)
> using the O0 option generates not-so-bad, slightly naive code with 52
> lines of assembly
> using O1 generates good code with 20 lines of assembly
> however when O2 is turned on the generated assembly blows up to 230 lines
> for this function!
> I am not sure if this is classified as a bug because the code does behave
> correctly however it is strange.
>

Have you measured the performance?

GCC -O2 does not target minimum code size and one should not assume that
smaller code is faster code given the details of processor
microarchitectures.

If you are reporting that -O2 is producing worse performance, then that is
a regression.  Large code size with -O2 is not a regression and may
actually be correct and beneficial because the option is intended to
improve performance, not reduce code size.

Thanks, David

Reply via email to