This is the mail archive of the gcc-bugs@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]

[Bug middle-end/54969] New: Bitfield test not optimised at -Os.


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: unassigned@gcc.gnu.org
        ReportedBy: suckfish@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)


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