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



             Bug #: 54969

           Summary: Bitfield test not optimised at -Os.

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: middle-end

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: suckf...@ihug.co.nz





Compiling with -Os, the compiler fails to detect that this loop will always

execute at least once:



unsigned get (void);

void go (void)

{

    unsigned f;

    for (f = 1; f & 1; f = get());

}



The relevant assembly output:



    jmp    .L2

.L3:

    call    get

.L2:

    testb    $1, %al

    jne    .L3



With -O2 gcc does better, and removes the first jmp, giving:



.L2:

    call    get

    testb    $1, %al

    jne    .L2



This happens both on x86-64 and arm:



gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)



arm-linux-gnu-gcc (GCC) 4.7.1 20120606 (Red Hat 4.7.1-0.1.20120606)

Reply via email to