mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-03 00:10:51 +02:00
+ more unary minus optimizations
* test extended
This commit is contained in:
parent
781da5e60d
commit
69d5d648a9
@ -972,6 +972,23 @@ implementation
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{
|
||||||
|
-(-left*right) or -(left*-right) => right*left
|
||||||
|
|
||||||
|
this operation is always valid as reals do not use a two's complement representation for negative
|
||||||
|
numbers, -real means just flip the sign bit
|
||||||
|
}
|
||||||
|
if (left.nodetype=muln) and ((taddnode(left).left.nodetype=unaryminusn)) then
|
||||||
|
begin
|
||||||
|
result:=caddnode.create(muln,taddnode(left).right.getcopy,tunaryminusnode(taddnode(left).left).left.getcopy);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
if (left.nodetype=muln) and ((taddnode(left).right.nodetype=unaryminusn)) then
|
||||||
|
begin
|
||||||
|
result:=caddnode.create(muln,taddnode(left).left.getcopy,tunaryminusnode(taddnode(left).right).left.getcopy);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
{ --node => node
|
{ --node => node
|
||||||
this operation is always valid as reals do not use a two's complement representation for negative
|
this operation is always valid as reals do not use a two's complement representation for negative
|
||||||
numbers, -real means just flip the sign bit
|
numbers, -real means just flip the sign bit
|
||||||
|
@ -44,5 +44,19 @@ begin
|
|||||||
if (d3<>0.0) or not(TDoubleRec(d3).Sign) then
|
if (d3<>0.0) or not(TDoubleRec(d3).Sign) then
|
||||||
halt(7);
|
halt(7);
|
||||||
|
|
||||||
|
d1:=1.0;
|
||||||
|
d2:=2.0;
|
||||||
|
d3:=-(d2*-d1);
|
||||||
|
writeln(d3);
|
||||||
|
if (d3<>2.0) or (TDoubleRec(d3).Sign) then
|
||||||
|
halt(8);
|
||||||
|
|
||||||
|
d1:=1.0;
|
||||||
|
d2:=2.0;
|
||||||
|
d3:=-(-d2*d1);
|
||||||
|
writeln(d3);
|
||||||
|
if (d3<>2.0) or (TDoubleRec(d3).Sign) then
|
||||||
|
halt(9);
|
||||||
|
|
||||||
writeln('ok');
|
writeln('ok');
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user