Преглед на файлове

+ do constant propagation into arguments of inline nodes if possible
+ do constant propagation into inc/dec nodes, if the node being identified as constant, is inc'ed/dec'ed

git-svn-id: trunk@34794 -

florian преди 8 години
родител
ревизия
6b84a1e1b8
променени са 1 файла, в които са добавени 23 реда и са изтрити 6 реда
  1. 23 6
      compiler/optconstprop.pas

+ 23 - 6
compiler/optconstprop.pas

@@ -58,7 +58,7 @@ unit optconstprop;
       fmodule,
       pass_1,procinfo,
       symsym, symconst,
-      nutils, nbas, ncnv, nld, nflw, ncal;
+      nutils, nbas, ncnv, nld, nflw, ncal, ninl;
 
     function check_written(var n: tnode; arg: pointer): foreachnoderesult;
       begin
@@ -192,17 +192,34 @@ unit optconstprop;
                   end;
               end;
           end
-        else if n.nodetype in [calln,inlinen] then
+        else if n.nodetype=inlinen then
           begin
-            if might_have_sideeffects(n) and (n.nodetype=inlinen) then
-              exit(false);
-
-            if n.nodetype=calln then
+            { constant inc'ed/dec'ed? }
+            if (tinlinenode(n).inlinenumber=in_dec_x) or (tinlinenode(n).inlinenumber=in_inc_x) then
+              begin
+                if not(assigned(tcallparanode(tinlinenode(n).left).right)) and
+                  tnode(tassignmentnode(arg).left).isequal(tcallparanode(tinlinenode(n).left).left) then
+                  begin
+                    { if the node just being searched is inc'ed/dec'ed then replace the inc/dec
+                      by add/sub and force a second replacement pass }
+                    oldnode:=n;
+                    n:=tinlinenode(n).getaddsub_for_incdec;
+                    oldnode.free;
+                    tree_modified:=true;
+                    { do not continue, value changed, if further const. propagations are possible, this is done
+                      by the next pass }
+                    result:=false;
+                    exit;
+                  end;
+              end
+            else if might_have_sideeffects(n) then
               exit(false);
 
             replaceBasicAssign(tunarynode(n).left, arg, tree_modified);
             result:=false;
           end
+        else if n.nodetype=calln then
+          exit(false)
         else if n.InheritsFrom(tbinarynode) then
           begin
             result:=replaceBasicAssign(tbinarynode(n).left, arg, tree_modified);