mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 05:59:28 +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
|
||||
t , vl: tnode;
|
||||
t , vl, hp: tnode;
|
||||
lt,rt : tnodetype;
|
||||
hdef,
|
||||
rd,ld : tdef;
|
||||
@ -727,6 +727,58 @@ implementation
|
||||
else
|
||||
;
|
||||
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;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
@ -759,11 +811,7 @@ implementation
|
||||
;
|
||||
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
|
||||
{$endif}
|
||||
begin
|
||||
case nodetype of
|
||||
muln:
|
||||
@ -771,6 +819,58 @@ implementation
|
||||
else
|
||||
;
|
||||
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;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
|
Loading…
Reference in New Issue
Block a user