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

This commit is contained in:
florian 2023-01-29 13:49:33 +01:00
parent ffd14f449d
commit 09b435cdab
3 changed files with 31 additions and 1 deletions

View File

@ -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
tests/tbs/tb0704.pp Normal file
View File

@ -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
tests/tbs/tb0705.pp Normal file
View File

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