mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 17:59:27 +02:00
+ more unary minus optimizations
* test extended
This commit is contained in:
parent
a58368d20d
commit
3e760b33c7
@ -959,6 +959,29 @@ implementation
|
||||
left:=nil;
|
||||
exit;
|
||||
end;
|
||||
if is_real(left.resultdef) then
|
||||
begin
|
||||
{
|
||||
-(left-right) => right-left
|
||||
|
||||
As this result in -(1.0-1.0)=0.0 instead of 0.0, this is only valid in fastmath mode
|
||||
}
|
||||
if (cs_opt_fastmath in current_settings.optimizerswitches) and (left.nodetype=subn) then
|
||||
begin
|
||||
result:=caddnode.create(subn,taddnode(left).right.getcopy,taddnode(left).left.getcopy);
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ --node => node
|
||||
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=unaryminusn then
|
||||
begin
|
||||
result:=tunarynode(left).left.getcopy;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -31,5 +31,18 @@ begin
|
||||
if (d3<>1.0) or (TDoubleRec(d3).Sign) then
|
||||
halt(5);
|
||||
|
||||
d1:=1.0;
|
||||
d2:=1.0;
|
||||
d3:=-(d2-d1);
|
||||
writeln(d3);
|
||||
if (d3<>0.0) or not(TDoubleRec(d3).Sign) then
|
||||
halt(6);
|
||||
|
||||
d1:=-0.0;
|
||||
d3:=--d1;
|
||||
writeln(d3);
|
||||
if (d3<>0.0) or not(TDoubleRec(d3).Sign) then
|
||||
halt(7);
|
||||
|
||||
writeln('ok');
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user