* optimize also -(x+1) and -(1+x) into not(x)

This commit is contained in:
florian 2024-03-06 22:56:06 +01:00
parent 2e6c3b060d
commit f41025f5dd
2 changed files with 20 additions and 0 deletions

View File

@ -1092,6 +1092,20 @@ implementation
result:=tunarynode(left).left.getcopy;
exit;
end;
end
{ transform -(x+1) or -(1+x) into not(x) }
else if is_integer(left.resultdef) and is_signed(left.resultdef) and (left.nodetype=addn) and ((localswitches*[cs_check_overflow,cs_check_range])=[]) then
begin
if is_constintnode(taddnode(left).right) and (tordconstnode(taddnode(left).right).value=1) then
begin
result:=cnotnode.create(taddnode(left).left.getcopy);
exit;
end
else if is_constintnode(taddnode(left).left) and (tordconstnode(taddnode(left).left).value=1) then
begin
result:=cnotnode.create(taddnode(left).right.getcopy);
exit;
end;
end;
end;

View File

@ -6,4 +6,10 @@ begin
if -l-1<>-1235 then
halt(1);
if -(l+1)<>-1235 then
halt(2);
if -(1+l)<>-1235 then
halt(2);
end.