This is the mail archive of the gcc@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] |
|
I want to provide a method to let GCC optimaze more than
before.
For example,if I input
{
int a=1,b=2,c=3,d=4;
int x=c+a+d;
int y=b+a;
int z=a+c+d+b;
}
GCC will assemble them to six addition
instruction
{
mov x,c add
x,a add x,d
mov y,b add
y,a
mov z,a add
z,c add z,d add z,b
}
but GCC can do more better,use four addition instruction other
than six
{
mov y(temp1),a add
y,b
mov
temp2,c add
temp2,d
mov
x,a add
x,temp2
mov z,y(temp1) add
z,temp2
}or{
int y(temp1)=a+b;
int temp2=c+d;
int x=a+temp2;
int z=temp2+y(temp1);
}
It's easy.I can provide an optimal method--Optimize Expression
by Sorting by Variable(OESV) to solved it easily.
OESV:The first,sort all variables by dictionary,and then
search all repeat expression and store them to temp variables,then
optimize.
For example,optimize above
First sort all variables:
{
int x=a+c+d;
int y=a+b;
int z=a+b+c+d;
}
Now,search all repeat expression about 'a',we will find 'a+b'
is used twice,so y=temp1=a+b,this we get a varible--temp1=y,
repeat continueouly we will find an other varible temp2=c+d,in
a word...it's easy to computer
With y(temp1) and temp2 help,we can optimaze more than
before,isn't it?
A Note:(about function)
{
int x=a+myfun(m+n);
int y=b+myfun(m+n)+a;
int myfun(k){return int
k+ret<<stdin;}//notice myfun implenments by stdin
}
If we product an optimazing temp=a+myfun(m+n),it isn't always
correct!Because myfun(k)!=myfun(k)!!(due to stdin,it's uncertain when call them
twice)
but the optimal method above is correct in the bulk cases
if we set up a table about <cmath> and sign all
function which fun(x)==fun(x),most programers will benefit from my
works.
That's all.If you have problems,email me!
gcc:2.95
I hope found OESV in GCC3.0
yfzhang
real name:Zhang Yunfeng(China) |
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |