Browse Source

* run constant propagation multiple times if needed and if slow optimizations are turned on

florian 1 year ago
parent
commit
0aa851b7f7
1 changed files with 12 additions and 10 deletions
  1. 12 10
      compiler/optconstprop.pas

+ 12 - 10
compiler/optconstprop.pas

@@ -55,7 +55,7 @@ unit optconstprop;
   implementation
 
     uses
-      globtype,
+      globtype, globals,
       pass_1,procinfo,compinnr,
       symsym, symconst,
       nutils, nbas, ncnv, nld, nflw, ncal, ninl,
@@ -395,19 +395,21 @@ unit optconstprop;
 
     function do_optconstpropagate(var rootnode: tnode;var changed: boolean): tnode;
       begin
+        repeat
 {$ifdef DEBUG_CONSTPROP}
-        writeln('************************ before constant propagation ***************************');
-        printnode(rootnode);
+          writeln('************************ before constant propagation ***************************');
+          printnode(rootnode);
 {$endif DEBUG_CONSTPROP}
-        changed:=false;
-        foreachnodestatic(pm_postandagain, rootnode, @propagate, @changed);
-        if changed then
-          doinlinesimplify(rootnode);
+          changed:=false;
+          foreachnodestatic(pm_postandagain, rootnode, @propagate, @changed);
+          if changed then
+            doinlinesimplify(rootnode);
 {$ifdef DEBUG_CONSTPROP}
-        writeln('************************ after constant propagation ***************************');
-        printnode(rootnode);
-        writeln('*******************************************************************************');
+          writeln('************************ after constant propagation ***************************');
+          printnode(rootnode);
+          writeln('*******************************************************************************');
 {$endif DEBUG_CONSTPROP}
+        until not(cs_opt_level3 in current_settings.optimizerswitches) or not(changed);
         result:=rootnode;
       end;