This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
type conversion....
- To: egcs at cygnus dot com
- Subject: type conversion....
- From: Jan Hubicka <hubicka at atrey dot karlin dot mff dot cuni dot cz>
- Date: Tue, 2 Jun 1998 11:57:23 +0200
Hi
I was experimenting a bit with egcs and tried to compile following example:
#include <stdio.h>
char a(void);
char b(void);
main()
{
unsigned short c=a()+b();
printf("%i\n",c);
}
Result is IMO quite bad
gcc2_compiled.:
.section .rodata
.LC0:
.string "%i\n"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
pushl %ebx
call a
movb %al,%bl
call b
movb %al,%dl
movsbw %bl,%ax
movsbw %dl,%dx
addl %eax,%edx
xorl %eax,%eax
movw %dx,%ax
pushl %eax
pushl $.LC0
call printf
movl -4(%ebp),%ebx
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) egcs-2.90.23 980102 (egcs-1.0.1 release)"
At least I don't understand, why it first saves return value to 8bit
register, and later moves to 16 bit...
I was trying to avoid this, but results was just crashing compiler :))
Anyway, other think should be, that whole add can be 32 bit, not 16 bit.
This should avoid the second conversion... so I started to think about way
to implement this...
I think it should be nice to add an interval information into each rtl,
and calculate the minimal and maximal values of each rtl and register.
This should let gcc to be much smarter about types, and propagate more
constants... For example when value is always in the interval 0-100, it should
convert it into unsigned char, wich should help at some platforms. At intel it
should convert char value to integer (in case overflow in the calculation can
not happend) and such. Also can convert signed to unsigned quite often IMO...
Calculating of intervals inside basic block should be easy, but not very
effective. I think it should be global, but calculating intervals in the
loops should be hard work. Only idea I have is following:
first calculate loop with original intervals in registers, then again, with
output intervals (this step should be repeated) and then intervals that still
changes change to +inf/-inf and repeat... this should quite quicky converge
IMO...
Also interval should be four values - minimal, maximal, possible set bits
and possible unsed..
the second information should behave better for operations like and/or etc...
Well, thats probably all... I am not sure how hard is this to implement...
I can imagine code for calculating the intervals inside basics block, but not
much more... I also think I saw similar idea somewhere in the docs.
I just wrote it here, because I think, it should be quite interesting feature...
Honza
--
OK. Lets make some signature file.
+-------------------------------------------------------------------------+
| Jan Hubicka (Jan Hubi\v{c}ka in TeX) hubicka@freesoft.cz |
| Czech free software foundation: http://www.freesoft.cz |
| AA project - the new way for comupter graphics - http://www.ta.jcu.cz/aa|
| homepage: http://www.paru.cas.cz/~hubicka/, games koules, Xonix, fast |
| fractal zoomer XaoS, index of Czech GNU/Linux/UN*X documentation etc. |
+-------------------------------------------------------------------------+