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]

optimization/6984: wrong code generated with -O2, -O3, -Os for do-while loop on PowerPC


>Number:         6984
>Category:       optimization
>Synopsis:       wrong code generated with -O2, -O3, -Os for do-while loop on PowerPC
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 10 08:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     fshvaige@cisco.com
>Release:        3.1
>Organization:
>Environment:
../gcc-3.1/configure --with-gcc-version-trigger=/home/install/gcc-3.1/gcc/version.c --host=i686-pc-linux-gnu --with-newlib --enable-target-optspace --target=ppc-eabi --prefix=/home/crossGCC/ppc-eabi --with-local-prefix=/home/crossGCC/ppc-eabi --program-prefix=ppc-eabi- --enable-languages=c,c++ -v --norecursion
>Description:
File test1.c:

void f1 (unsigned n) {
        do {
        } while (--n);
}
void f2 (unsigned n) {
l1:
        if (--n) goto l1;
}

When compiled with:
ppc-eabi-gcc -v -save-temps -c -O2 -Wall test1.c

Produces wrong-large-ugly code for function f1().
The same for -O3 and -Os.
For -O1 all Ok.

Note: code for function f2() always Ok.
>How-To-Repeat:
compile test1.c:

void f1 (unsigned n) {
        do {
        } while (--n);
}
void f2 (unsigned n) {
l1:
        if (--n) goto l1;
}

with command line like:
ppc-eabi-gcc -v -save-temps -c -O2 -Wall test1.c

and see file test1.s:
        .file   "test1.c"
        .section        ".text"
        .align 2
        .globl f1
        .type   f1,@function
f1:
        cmpwi 0,3,0
        bne- 0,.L7
        li 3,1
.L7:
        mtctr 3
.L6:
        bdnz .L6
        blr
.Lfe1:
        .size   f1,.Lfe1-f1
        .align 2
        .globl f2
        .type   f2,@function
f2:
        mtctr 3
.L9:
        bdnz .L9
        blr
.Lfe2:
        .size   f2,.Lfe2-f2
        .ident  "GCC: (GNU) 3.1"

Code for f1() must be the same as for f2().
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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