Browse Source

* more fixes for loop strength reduction

git-svn-id: trunk@43912 -
florian 5 years ago
parent
commit
aabd7c7217
2 changed files with 11 additions and 4 deletions
  1. 3 3
      compiler/optloop.pas
  2. 8 1
      compiler/optutils.pas

+ 3 - 3
compiler/optloop.pas

@@ -266,7 +266,7 @@ unit optloop;
                 { no aliasing? }
                 { no aliasing? }
                 result:=not(tabstractvarsym(tloadnode(expr).symtableentry).addr_taken) and
                 result:=not(tabstractvarsym(tloadnode(expr).symtableentry).addr_taken) and
                 { no definition in the loop? }
                 { no definition in the loop? }
-                  not(DFASetIn(loop.optinfo^.defsum,expr.optinfo^.index));
+                  not(DFASetIn(tfornode(loop).t2.optinfo^.defsum,expr.optinfo^.index));
             end;
             end;
           vecn:
           vecn:
             begin
             begin
@@ -375,8 +375,7 @@ unit optloop;
 
 
                       addstatement(initcodestatements,tempnode);
                       addstatement(initcodestatements,tempnode);
                       addstatement(initcodestatements,cassignmentnode.create(ctemprefnode.create(tempnode),
                       addstatement(initcodestatements,cassignmentnode.create(ctemprefnode.create(tempnode),
-                        caddnode.create(muln,
-                          caddnode.create(subn,tfornode(arg).right.getcopy,cordconstnode.create(1,tfornode(arg).right.resultdef,false)),
+                        caddnode.create(muln,tfornode(arg).right.getcopy,
                           taddnode(n).right.getcopy)
                           taddnode(n).right.getcopy)
                         )
                         )
                       );
                       );
@@ -396,6 +395,7 @@ unit optloop;
             begin
             begin
               { is the index the counter variable? }
               { is the index the counter variable? }
               if not(is_special_array(tvecnode(n).left.resultdef)) and
               if not(is_special_array(tvecnode(n).left.resultdef)) and
+                not(is_packed_array(tvecnode(n).left.resultdef)) and
                 (tvecnode(n).right.isequal(tfornode(arg).left) or
                 (tvecnode(n).right.isequal(tfornode(arg).left) or
                  { fpc usually creates a type cast to access an array }
                  { fpc usually creates a type cast to access an array }
                  ((tvecnode(n).right.nodetype=typeconvn) and
                  ((tvecnode(n).right.nodetype=typeconvn) and

+ 8 - 1
compiler/optutils.pas

@@ -348,7 +348,14 @@ unit optutils;
     function adddef(var n: tnode; arg: pointer): foreachnoderesult;
     function adddef(var n: tnode; arg: pointer): foreachnoderesult;
       begin
       begin
         if assigned(n.optinfo) then
         if assigned(n.optinfo) then
-          DFASetIncludeSet(defsum,n.optinfo^.def);
+          begin
+            DFASetIncludeSet(defsum,n.optinfo^.def);
+            { for nodes itself do not necessarily expose the definition of the counter as
+              the counter might be undefined after the for loop, so include here the counter
+              explicitly }
+            if (n.nodetype=forn) and assigned(tfornode(n).left.optinfo) then
+              DFASetInclude(defsum,tfornode(n).left.optinfo^.index);
+          end;
         Result:=fen_false;
         Result:=fen_false;
       end;
       end;