summaryrefslogtreecommitdiff
path: root/compiler/nadd.pas
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-06-08 20:33:27 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-06-08 20:33:27 +0000
commita10f5600409e1aacb02d8814e8ea95b51d37aa9e (patch)
tree0df74d62ec668528098225439e3905570e6e5cea /compiler/nadd.pas
parent34cf9a90a13913ebd5b3c7ae85098bf9bcb82351 (diff)
downloadfpc-a10f5600409e1aacb02d8814e8ea95b51d37aa9e.tar.gz
+ optimize real operations with 0 and 1 if fast math is turned on
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@45627 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'compiler/nadd.pas')
-rw-r--r--compiler/nadd.pas67
1 files changed, 67 insertions, 0 deletions
diff --git a/compiler/nadd.pas b/compiler/nadd.pas
index 4c91a72d35..ae7c453f45 100644
--- a/compiler/nadd.pas
+++ b/compiler/nadd.pas
@@ -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 }