+ optimize real operations with 0 and 1 if fast math is turned on

git-svn-id: trunk@45627 -
This commit is contained in:
florian 2020-06-08 20:33:27 +00:00
parent 8a9178f00a
commit aafc22bd74
2 changed files with 68 additions and 1 deletions

View File

@ -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 }

View File

@ -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 }