mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-09 03:49:05 +02:00
+ optimize real operations with 0 and 1 if fast math is turned on
git-svn-id: trunk@45627 -
This commit is contained in:
parent
8a9178f00a
commit
aafc22bd74
@ -950,6 +950,73 @@ implementation
|
||||
include(result.flags,nf_is_currency);
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ optimize operations with real constants, but only if fast math is switched on as
|
||||
the operations could change the sign of 0
|
||||
}
|
||||
if cs_opt_fastmath in current_settings.optimizerswitches then
|
||||
begin
|
||||
if lt=realconstn then
|
||||
begin
|
||||
if (trealconstnode(left).value_real=0) and (nodetype in [addn,muln,subn,slashn]) then
|
||||
begin
|
||||
case nodetype of
|
||||
addn:
|
||||
begin
|
||||
result:=right.getcopy;
|
||||
exit;
|
||||
end;
|
||||
slashn,
|
||||
muln:
|
||||
if not(might_have_sideeffects(right,[mhs_exceptions])) then
|
||||
begin
|
||||
result:=left.getcopy;
|
||||
exit;
|
||||
end;
|
||||
subn:
|
||||
begin
|
||||
result:=cunaryminusnode.create(right.getcopy);
|
||||
exit;
|
||||
end;
|
||||
else
|
||||
Internalerror(2020060801);
|
||||
end;
|
||||
end
|
||||
else if (trealconstnode(left).value_real=1) and (nodetype=muln) then
|
||||
begin
|
||||
result:=right.getcopy;
|
||||
exit;
|
||||
end;
|
||||
end
|
||||
else if rt=realconstn then
|
||||
begin
|
||||
if (trealconstnode(right).value_real=0) and (nodetype in [addn,muln,subn]) then
|
||||
begin
|
||||
case nodetype of
|
||||
subn,
|
||||
addn:
|
||||
begin
|
||||
result:=left.getcopy;
|
||||
exit;
|
||||
end;
|
||||
muln:
|
||||
if not(might_have_sideeffects(left,[mhs_exceptions])) then
|
||||
begin
|
||||
result:=right.getcopy;
|
||||
exit;
|
||||
end;
|
||||
else
|
||||
Internalerror(2020060802);
|
||||
end;
|
||||
end
|
||||
else if (trealconstnode(right).value_real=1) and (nodetype in [muln,slashn]) then
|
||||
begin
|
||||
result:=left.getcopy;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$if (FPC_FULLVERSION>20700) and not defined(FPC_SOFT_FPUX80)}
|
||||
{ bestrealrec is 2.7.1+ only }
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
{ %OPT=-CE }
|
||||
{ %OPT=-CE -Oonofastmath }
|
||||
{ %RESULT=207 }
|
||||
{ Source provided for Free Pascal Bug Report 3160 }
|
||||
{ Submitted by "Michalis Kamburelis" on 2004-06-12 }
|
||||
|
Loading…
Reference in New Issue
Block a user