This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimizations and the -pedantic option


>
>  The effect is that a pedantic compilation sees an add of the variable
>  where a non-pedantic compilation sees an add of the constant 1.  This
>  then leads to slightly different generated code, which causes the
>  non-pedantic compilation to fail to see that it can generate a tail
>  call.
>

A curious effect.

It seems that a transformation that is supposed to help optimization
(seeing j as a constant value instead of a variable) has a negative
effect. I've tried to simplify the code in order to isolate the issue
and I've produced the following functions:

int recur_1(int i)
{
    if (i-- <= 0) return 0;
    return (i + 1) + recur_1(i);
}

int recur_2(int i)
{
    if (i-- <= 0) return 0;
    {
        int j = i + 1;
        return j + recur_2(i);
    }
}

The optimizer (gcc version is 4.1.2) behaves much better with the
second function. I'm wondering what mysterious beast lurks in the
optimization routines...  :)

    Dario


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]