http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53252

             Bug #: 53252
           Summary: Missed shrink wrapping opportunity
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: l...@redhat.com


Compile the attached code with -O3 -fprofile-generate, run the resulting
executable, then compile again with -O3 -fprofile-use.

Ideally the fast path through main_func would just do something like

test %dil,%dil
jnz <slow path>
xor %eax,%eax
ret

Unfortunately, we're getting frame setup/teardown in the fast path.

testcode:

#include <stdio.h>
volatile long x = 13;
void bar(long v)
{
    printf("l = %li\n", v);
}

long foo(long l)
{
    for (int i = 0; i != x; ++i)
    {
        l *= l ^ 47110815;
        bar(l);
    }

    return l;
}

int main_func(bool b) __attribute__((noinline));
int main_func(bool b)
{
    int ret = 0;
    if (b)
    {
        for ( int i = 0; i != 1000; ++i )
            ret += foo(i);
    }
    return ret;
}

int main( int argc, char** argv)
{
    return main_func(argc != 1);
}

Reply via email to