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]

Serious optimization bug in egcs-2.91.66 for the i386-redhat-linux target


Here's a simple example to reproduce the bug. I've also attached the
'-S' output for -O2, which shows that the ebx register gets incorrectly
optimised out.

I've narrowed the bug to the flow analysis stage of the compiler
(flow.c), but not being a compiler optimization expert, am not sure how
to proceed.

Any help or insights in getting around this problem would be greatly
appreciated.

Thanks
- Bhavesh

-- 
Bhavesh P. Davda
Lucent Technologies, Bell Labs
Room 37W15                      E-mail : bhavesh@lucent.com
11900 N Pecos St                Phone  : (303) 538-4438
Westminster, CO 80234           Fax    : (303) 538-3155
---------------------------try.c------------------------
struct mystruct {
	unsigned char a;
	unsigned char b;
	unsigned char c;
	unsigned char d;
};

int main()
{
	unsigned long mylong;

	mylong = 0x12345678;
	printf("mylong = 0x%08lx\n", mylong);
	((struct mystruct *)&mylong)->a = 0xab;
	printf("mylong = 0x%08lx\n", mylong);
}
----------------------end--try.c------------------------

$ /usr/bin/egcs -g3 -O0 -o try0 try.c
$ /usr/bin/egcs -g3 -O2 -o try2 try.c
$ /usr/bin/egcs -g3 -O2 -S -fverbose-asm -o try2.s try.c

$ ./try0
mylong = 0x12345678
mylong = 0x123456ab

$ ./try2
mylong = 0x12345678
mylong = 0x000000ab

-----------------------try2.s----------------------------
	.file	"try.c"
	.version	"01.01"
# GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
# options passed:  -g3 -O2 -fverbose-asm
# options enabled:  -fdefer-pop -fcse-follow-jumps -fcse-skip-blocks
# -fexpensive-optimizations -fthread-jumps -fstrength-reduce -fpeephole
# -fforce-mem -ffunction-cse -finline -fkeep-static-consts -fcaller-saves
# -fpcc-struct-return -fgcse -frerun-cse-after-loop -frerun-loop-opt
# -fschedule-insns2 -fcommon -fverbose-asm -fgnu-linker -fregmove
# -foptimize-register-move -fargument-alias -m80387 -mhard-float
# -mno-soft-float -mieee-fp -mfp-ret-in-387 -mschedule-prologue -mcpu=i386
# -march=pentium

.stabs "/root/src/gccbug/",100,0,0,.Ltext0
.stabs "try.c",100,0,0,.Ltext0
.text
.Ltext0:
	.stabs	"gcc2_compiled.", 0x3c, 0, 0, 0
.stabs "int:t(0,1)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0
.stabs "long int:t(0,3)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "unsigned int:t(0,4)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long unsigned int:t(0,5)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long long int:t(0,6)=r(0,1);01000000000000000000000;0777777777777777777777;",128,0,0,0
.stabs "long long unsigned int:t(0,7)=r(0,1);0000000000000;01777777777777777777777;",128,0,0,0
.stabs "short int:t(0,8)=r(0,8);-32768;32767;",128,0,0,0
.stabs "short unsigned int:t(0,9)=r(0,9);0;65535;",128,0,0,0
.stabs "signed char:t(0,10)=r(0,10);-128;127;",128,0,0,0
.stabs "unsigned char:t(0,11)=r(0,11);0;255;",128,0,0,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
.stabs "double:t(0,13)=r(0,1);8;0;",128,0,0,0
.stabs "long double:t(0,14)=r(0,1);12;0;",128,0,0,0
.stabs "complex int:t(0,15)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0
.stabs "complex float:t(0,16)=r(0,16);4;0;",128,0,0,0
.stabs "complex double:t(0,17)=r(0,17);8;0;",128,0,0,0
.stabs "complex long double:t(0,18)=r(0,18);12;0;",128,0,0,0
.stabs "void:t(0,19)=(0,19)",128,0,0,0
.stabs "mystruct:T(0,20)=s4a:(0,11),0,8;b:(0,11),8,8;\\",128,0,0,0
.stabs "c:(0,11),16,8;d:(0,11),24,8;;",128,0,0,0
.section	.rodata
.LC0:
	.string	"mylong = 0x%08lx\n"
.text
	.align 4
.stabs "main:F(0,1)",36,0,9,main
.globl main
	.type	 main,@function
main:
.stabn 68,0,9,.LM1-main
.LM1:
.LBB2:
.LBE2:
	pushl %ebp
	movl %esp,%ebp
.stabn 68,0,13,.LM2-main
.LM2:
	pushl $305419896
	pushl $.LC0
	call printf
.stabn 68,0,15,.LM3-main
.LM3:
	pushl $171
	pushl $.LC0
	call printf
.stabn 68,0,16,.LM4-main
.LM4:
	leave
	ret
.Lfe1:
	.size	 main,.Lfe1-main
.stabn 192,0,0,.LBB2-main
.stabn 224,0,0,.LBE2-main
.Lscope0:
.stabs "",36,0,0,.Lscope0-main
	.stabs "",100,0,0,.Letext
.Letext:
	.ident	"GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"
-----------------end---try2.s----------------------------

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