Bladeren bron

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

git-svn-id: trunk@45627 -
florian 5 jaren geleden
bovenliggende
commit
aafc22bd74
2 gewijzigde bestanden met toevoegingen van 68 en 1 verwijderingen
  1. 67 0
      compiler/nadd.pas
  2. 1 1
      tests/webtbs/tw3160a.pp

+ 67 - 0
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 }
 

+ 1 - 1
tests/webtbs/tw3160a.pp

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