This is the mail archive of the
egcs-bugs@egcs.cygnus.com
mailing list for the EGCS project.
Too optimized and not so much optimized code
- To: egcs-bugs@egcs.cygnus.com
- Subject: Too optimized and not so much optimized code
- From: mitr@email.cz
- Date: Tue, 6 Jul 1999 20:35:39 +0200
I came across a bit strange egcs-1.1.2 behaviour
-----------------------------
$ cat > tst.c
-----------------------------
unsigned
expand (char s)
{
unsigned x;
x = 0;
*(char *)&x = s;
return x;
}
unsigned
mult_256 (char s)
{
unsigned x;
x = 0;
((char *)&x)[1] = s;
return x;
}
-----------------------------
$ egcs -O2 -fomit-frame-pointer -S tst.c
$ cat tst.s
-----------------------------
.file "tst.c"
.version "01.01"
gcc2_compiled.:
.text
.align 4
.globl expand
.type expand,@function
expand:
movl 4(%esp),%eax
ret
.Lfe1:
.size expand,.Lfe1-expand
.align 4
.globl mult_256
.type mult_256,@function
mult_256:
subl $4,%esp
movl 8(%esp),%eax
movl $0,(%esp)
movb %al,1(%esp)
movl (%esp),%eax
popl %ecx
ret
.Lfe2:
.size mult_256,.Lfe2-mult_256
.ident "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)"
------------------------------
(Yes, I know that it is not portable)
1) don't you think that expand () is overoptimized ? IMHO it should look
like
this:
expand:
movzbl 4(%esp),%eax
ret
2) the mult_256 () is here for two reasons:
a) it is compiled reasonably, so one would conclude that expand () should
too
b) instead of the last three insns the following should be generated
popl %eax
ret
Thanks for the time you spend while developing egcs.
Mirek
--- CREATED BY ATC O..R..G..A..N..I..Z..E..R
--- http://email.cz <--- Get Your Free Email