Просмотр исходного кода

* transform a/a only into 1 if fastmath is on

florian 2 лет назад
Родитель
Сommit
09b435cdab
3 измененных файлов с 31 добавлено и 1 удалено
  1. 3 1
      compiler/nadd.pas
  2. 14 0
      tests/tbs/tb0704.pp
  3. 14 0
      tests/tbs/tb0705.pp

+ 3 - 1
compiler/nadd.pas

@@ -1142,7 +1142,9 @@ implementation
                       end;
                   end
                 { optimize a/a and a-a }
-                else if (cs_opt_level2 in current_settings.optimizerswitches) and  (nodetype in [slashn,subn]) and
+                else if (((cs_opt_level2 in current_settings.optimizerswitches) and (nodetype=subn)) or
+                    (([cs_opt_fastmath,cs_opt_level2]*current_settings.optimizerswitches=[cs_opt_fastmath,cs_opt_level2]) and (nodetype=slashn))
+                  ) and
                   left.isequal(right) and not(might_have_sideeffects(left,[mhs_exceptions])) then
                   begin
                     case nodetype of

+ 14 - 0
tests/tbs/tb0704.pp

@@ -0,0 +1,14 @@
+{ %opt=-Oonofastmath -CE -Oonoconstprop }
+{$mode objfpc}
+uses
+  sysutils;
+var
+  a : real;
+begin
+  try
+    writeln(a/a);
+  except
+    halt(0);
+  end;
+  halt(1);
+end.

+ 14 - 0
tests/tbs/tb0705.pp

@@ -0,0 +1,14 @@
+{ %opt=-O4 -CE -Oonoconstprop }
+{$mode objfpc}
+uses
+  sysutils;
+var
+  a : real;
+begin
+  try
+    writeln(a/a);
+  except
+    halt(1);
+  end;
+  halt(0);
+end.