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]

FW: Bug in cc1 - wrong/incosistent code




Hi,
Preface:
I'm developing a GCC based cross-compiler for our CompactRISC family of
16-bit processors. The bug described below occured on our modified compiler
which includes many changes from the original GCC sources that I cannot list
here, but I believe that the bug is not induced by these changes.  I'm
including assembly code for our architecture, which I believe is
straighforward enough to understand.
GCC version:	2.95.1 + hand merging of 2.95.2 changes Input file:
int *pa;
void f()
	{
*(pa++) = *(pa++) + *(pa++);
	}

Command arguments: -O
Operating system: Windows NT, using MSVC cl compiler.
Bug description:
The compiler generates for the source code above functionally different code
when compiled
with -O and withou it, and both outputs are functionally different from the
code generated
by our GCC 2.7.2 based compiler.

1.	Version 2.95.1 compiled with -O:
Effectively the assembly code is doing: *(pa++) = *pa + *pa;
	...
_f:
#--- *(pa++) = *(pa++) + *(pa++);
        movw    $_pa,r2
        loadw   0(r2),r1
        loadw   0(r1),r0
        addw    r0,r0
        storw   r0,0(r1)
        addw    $2,r1
        storw   r1,0(r2)
        ...

2.	Version 2.95.1 compiled without -O.
Effectively the assembly code is doing: *pa = *pa + *pa; pa += 3;
	...
_f:
		push    $1,r7
#--- *(pa++) = *(pa++) + *(pa++);
        movw    $_pa,r7
        loadw   0(r7),r4
        movw    $_pa,r6
        loadw   0(r6),r3
        movw    $_pa,r5
        loadw   0(r5),r2
        loadw   0(r3),r0
        loadw   0(r2),r1
        addw    r1,r0
        storw   r0,0(r4)
        addw    $2,r2
        storw   r2,0(r5)
        addw    $2,r3
        storw   r3,0(r6)
        addw    $2,r4
        storw   r4,0(r7)
	...

3.	Version 2.7.2 compiled with -O (code is correct):
	...
#--- *(pa++) = *(pa++) + *(pa++);
        movw    $_pa,r1
        loadw   0(r1),r2
        movw    r2,r0
        addw    $6,r0
        storw   r0,0(r1)
        loadw   2(r2),r0
        loadw   4(r2),r1
        addw    r1,r0
        storw   r0,0(r2)
	...

Thank you for your help,
Irit Mano
National Semiconductor

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