mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 09:19:23 +02:00
+ optimize integer expressions like 2*x*4; which were not found by the node simplifier yet
git-svn-id: trunk@43577 -
This commit is contained in:
parent
94b728005d
commit
acdff47554
@ -477,7 +477,7 @@ implementation
|
|||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
t , vl: tnode;
|
t , vl, hp: tnode;
|
||||||
lt,rt : tnodetype;
|
lt,rt : tnodetype;
|
||||||
hdef,
|
hdef,
|
||||||
rd,ld : tdef;
|
rd,ld : tdef;
|
||||||
@ -727,6 +727,58 @@ implementation
|
|||||||
else
|
else
|
||||||
;
|
;
|
||||||
end;
|
end;
|
||||||
|
end
|
||||||
|
{ try to fold
|
||||||
|
op
|
||||||
|
/ \
|
||||||
|
op const1
|
||||||
|
/ \
|
||||||
|
const2 val
|
||||||
|
}
|
||||||
|
else if left.nodetype=nodetype then
|
||||||
|
begin
|
||||||
|
if is_constintnode(taddnode(left).left) then
|
||||||
|
begin
|
||||||
|
case left.nodetype of
|
||||||
|
xorn,
|
||||||
|
addn,
|
||||||
|
andn,
|
||||||
|
orn,
|
||||||
|
muln:
|
||||||
|
begin
|
||||||
|
hp:=right;
|
||||||
|
right:=taddnode(left).right;
|
||||||
|
taddnode(left).right:=hp;
|
||||||
|
left:=left.simplify(false);
|
||||||
|
result:=getcopy;
|
||||||
|
result.resultdef:=nil;
|
||||||
|
do_typecheckpass(result);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else if is_constintnode(taddnode(left).right) then
|
||||||
|
begin
|
||||||
|
case left.nodetype of
|
||||||
|
xorn,
|
||||||
|
addn,
|
||||||
|
andn,
|
||||||
|
orn,
|
||||||
|
muln:
|
||||||
|
begin
|
||||||
|
hp:=right;
|
||||||
|
right:=taddnode(left).left;
|
||||||
|
taddnode(left).left:=hp;
|
||||||
|
left:=left.simplify(false);
|
||||||
|
result:=getcopy;
|
||||||
|
result.resultdef:=nil;
|
||||||
|
do_typecheckpass(result);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
;
|
||||||
|
end;
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
if assigned(result) then
|
if assigned(result) then
|
||||||
exit;
|
exit;
|
||||||
@ -759,11 +811,7 @@ implementation
|
|||||||
;
|
;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
{$ifdef VER2_2}
|
|
||||||
else if (tordconstnode(left).value.svalue = -1) and (tordconstnode(left).value.signed) then
|
|
||||||
{$else}
|
|
||||||
else if tordconstnode(left).value = -1 then
|
else if tordconstnode(left).value = -1 then
|
||||||
{$endif}
|
|
||||||
begin
|
begin
|
||||||
case nodetype of
|
case nodetype of
|
||||||
muln:
|
muln:
|
||||||
@ -771,6 +819,58 @@ implementation
|
|||||||
else
|
else
|
||||||
;
|
;
|
||||||
end;
|
end;
|
||||||
|
end
|
||||||
|
{ try to fold
|
||||||
|
op
|
||||||
|
/ \
|
||||||
|
const1 op
|
||||||
|
/ \
|
||||||
|
const2 val
|
||||||
|
}
|
||||||
|
else if right.nodetype=nodetype then
|
||||||
|
begin
|
||||||
|
if is_constintnode(taddnode(right).left) then
|
||||||
|
begin
|
||||||
|
case right.nodetype of
|
||||||
|
xorn,
|
||||||
|
addn,
|
||||||
|
andn,
|
||||||
|
orn,
|
||||||
|
muln:
|
||||||
|
begin
|
||||||
|
hp:=left;
|
||||||
|
left:=taddnode(right).right;
|
||||||
|
taddnode(right).right:=hp;
|
||||||
|
right:=right.simplify(false);
|
||||||
|
result:=getcopy;
|
||||||
|
result.resultdef:=nil;
|
||||||
|
do_typecheckpass(result);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else if is_constintnode(taddnode(right).right) then
|
||||||
|
begin
|
||||||
|
case right.nodetype of
|
||||||
|
xorn,
|
||||||
|
addn,
|
||||||
|
andn,
|
||||||
|
orn,
|
||||||
|
muln:
|
||||||
|
begin
|
||||||
|
hp:=left;
|
||||||
|
left:=taddnode(right).left;
|
||||||
|
taddnode(right).left:=hp;
|
||||||
|
right:=right.simplify(false);
|
||||||
|
result:=getcopy;
|
||||||
|
result.resultdef:=nil;
|
||||||
|
do_typecheckpass(result);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
;
|
||||||
|
end;
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
if assigned(result) then
|
if assigned(result) then
|
||||||
exit;
|
exit;
|
||||||
|
Loading…
Reference in New Issue
Block a user