* transform -1-x into not(x)

This commit is contained in:
florian 2024-03-08 22:42:26 +01:00
parent 5086cf7e72
commit 594d4cc4f9
2 changed files with 13 additions and 2 deletions

View File

@ -916,8 +916,15 @@ implementation
{ Deal with anti-commutative subtraction }
if (nodetype = subn) then
begin
{ transform -1-x into not(x) }
if is_signed(rd) and is_constintnode(left) and (tordconstnode(left).value=-1) then
begin
result:=cnotnode.create(right.getcopy);
exit;
end
{ change "0 - val" to "-val" }
if is_constintnode(left) and (is_integer(right.resultdef) or is_pointer(right.resultdef)) then
else if is_constintnode(left) and (is_integer(right.resultdef) or is_pointer(right.resultdef)) then
begin
if (tordconstnode(left).value = 0) then
result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef);

View File

@ -1,3 +1,4 @@
{ %opt=-O- -O1 }
var
l : longint;
@ -11,5 +12,8 @@ begin
halt(2);
if -(1+l)<>-1235 then
halt(2);
halt(3);
if -1-l<>-1235 then
halt(4);
end.