mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-26 13:09:26 +02:00
* optimize also -(x+1) and -(1+x) into not(x)
This commit is contained in:
parent
2e6c3b060d
commit
f41025f5dd
@ -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;
|
||||
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user