* fold also pointer additions/subtractions

git-svn-id: trunk@44199 -
This commit is contained in:
florian 2020-02-16 20:14:28 +00:00
parent 17158c3587
commit 93521ae8e8

View File

@ -701,7 +701,7 @@ implementation
end; end;
{ Add,Sub,Mul,Or,Xor,Andn 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) or is_pointer(left.resultdef)) then
begin begin
if tordconstnode(right).value = 0 then if tordconstnode(right).value = 0 then
begin begin
@ -737,11 +737,11 @@ implementation
end; end;
end end
{ try to fold { try to fold
op op op
/ \ / \ / \
op const1 op const1 or op const1
/ \ / \ / \
const2 val const2 val val const2
} }
else if (left.nodetype=nodetype) and else if (left.nodetype=nodetype) and
{ there might be a mul operation e.g. longint*longint => int64 in this case { there might be a mul operation e.g. longint*longint => int64 in this case
@ -776,10 +776,12 @@ implementation
orn, orn,
muln: muln:
begin begin
hp:=right; { keep the order of val+const else pointer operations might cause an error }
right:=taddnode(left).left; hp:=taddnode(left).left;
taddnode(left).left:=hp; taddnode(left).left:=right;
left:=left.simplify(false); left:=left.simplify(false);
right:=left;
left:=hp;
result:=GetCopyAndTypeCheck; result:=GetCopyAndTypeCheck;
end; end;
else else
@ -790,7 +792,7 @@ implementation
if assigned(result) then if assigned(result) then
exit; exit;
end; end;
if is_constintnode(left) and is_integer(right.resultdef) then if is_constintnode(left) and (is_integer(right.resultdef) or is_pointer(right.resultdef)) then
begin begin
if tordconstnode(left).value = 0 then if tordconstnode(left).value = 0 then
begin begin