mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-27 13:09:43 +02:00
* improve simplification of arithmetic nodes, based on a patch by Jeppe Johansen
git-svn-id: trunk@25957 -
This commit is contained in:
parent
d4b6406e62
commit
d39b9059d6
@ -553,15 +553,15 @@ implementation
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Add,Sub,Mul with constant 0, 1 or -1? }
|
{ Add,Sub,Mul,Or,Xor,Andn with constant 0, 1 or -1? }
|
||||||
if is_constintnode(right) and is_integer(left.resultdef) then
|
if is_constintnode(right) and is_integer(left.resultdef) then
|
||||||
begin
|
begin
|
||||||
if tordconstnode(right).value = 0 then
|
if tordconstnode(right).value = 0 then
|
||||||
begin
|
begin
|
||||||
case nodetype of
|
case nodetype of
|
||||||
addn,subn:
|
addn,subn,orn,xorn:
|
||||||
result := left.getcopy;
|
result := left.getcopy;
|
||||||
muln:
|
andn,muln:
|
||||||
result:=cordconstnode.create(0,resultdef,true);
|
result:=cordconstnode.create(0,resultdef,true);
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
@ -591,11 +591,11 @@ implementation
|
|||||||
if tordconstnode(left).value = 0 then
|
if tordconstnode(left).value = 0 then
|
||||||
begin
|
begin
|
||||||
case nodetype of
|
case nodetype of
|
||||||
addn:
|
addn,orn,xorn:
|
||||||
result := right.getcopy;
|
result := right.getcopy;
|
||||||
subn:
|
subn:
|
||||||
result := cunaryminusnode.create(right.getcopy);
|
result := cunaryminusnode.create(right.getcopy);
|
||||||
muln:
|
andn,muln:
|
||||||
result:=cordconstnode.create(0,right.resultdef,true);
|
result:=cordconstnode.create(0,right.resultdef,true);
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
@ -2767,7 +2767,7 @@ implementation
|
|||||||
hp : tnode;
|
hp : tnode;
|
||||||
{$endif addstringopt}
|
{$endif addstringopt}
|
||||||
rd,ld : tdef;
|
rd,ld : tdef;
|
||||||
i : longint;
|
i,i2 : longint;
|
||||||
lt,rt : tnodetype;
|
lt,rt : tnodetype;
|
||||||
{$ifdef cpuneedsmulhelper}
|
{$ifdef cpuneedsmulhelper}
|
||||||
procname : string[32];
|
procname : string[32];
|
||||||
@ -2815,18 +2815,20 @@ implementation
|
|||||||
(((left.nodetype = ordconstn) and
|
(((left.nodetype = ordconstn) and
|
||||||
ispowerof2(tordconstnode(left).value,i)) or
|
ispowerof2(tordconstnode(left).value,i)) or
|
||||||
((right.nodetype = ordconstn) and
|
((right.nodetype = ordconstn) and
|
||||||
ispowerof2(tordconstnode(right).value,i))) then
|
ispowerof2(tordconstnode(right).value,i2))) then
|
||||||
begin
|
begin
|
||||||
if left.nodetype = ordconstn then
|
if ((left.nodetype = ordconstn) and
|
||||||
|
ispowerof2(tordconstnode(left).value,i)) then
|
||||||
begin
|
begin
|
||||||
tordconstnode(left).value := i;
|
tordconstnode(left).value := i;
|
||||||
result := cshlshrnode.create(shln,right,left);
|
result := cshlshrnode.create(shln,right,left);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
tordconstnode(right).value := i;
|
tordconstnode(right).value := i2;
|
||||||
result := cshlshrnode.create(shln,left,right);
|
result := cshlshrnode.create(shln,left,right);
|
||||||
end;
|
end;
|
||||||
|
result.resultdef := resultdef;
|
||||||
left := nil;
|
left := nil;
|
||||||
right := nil;
|
right := nil;
|
||||||
exit;
|
exit;
|
||||||
|
Loading…
Reference in New Issue
Block a user