Browse Source

* Fixed a register allocator bug
* Figured out why -dnewra generates superfluous "mov reg1,reg2"
statements: changes in location_force. These moves are now no longer
constrained so they are optimized away.

daniel 22 years ago
parent
commit
557ac8b02e
2 changed files with 23 additions and 3 deletions
  1. 11 1
      compiler/ncgutil.pas
  2. 12 2
      compiler/rgobj.pas

+ 11 - 1
compiler/ncgutil.pas

@@ -427,6 +427,8 @@ implementation
                rg.ungetregisterint(list,l.registerhigh);
                rg.ungetregisterint(list,l.registerhigh);
                l.registerhigh.enum:=R_NO;
                l.registerhigh.enum:=R_NO;
              end;
              end;
+            if l.loc=LOC_REGISTER then
+              rg.ungetregisterint(list,l.register);
            {Do not bother to recycle the existing register. The register
            {Do not bother to recycle the existing register. The register
             allocator eliminates unnecessary moves, so it's not needed
             allocator eliminates unnecessary moves, so it's not needed
             and trying to recycle registers can cause problems because
             and trying to recycle registers can cause problems because
@@ -513,6 +515,7 @@ implementation
                  if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
                  if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
                    l.size:=dst_size;
                    l.size:=dst_size;
 {$endif not i386}
 {$endif not i386}
+{$ifndef newra}
                  { Release old register when the superregister is changed }
                  { Release old register when the superregister is changed }
                  if (l.loc=LOC_REGISTER) and
                  if (l.loc=LOC_REGISTER) and
                     (l.register.number shr 8<>hregister.number shr 8) then
                     (l.register.number shr 8<>hregister.number shr 8) then
@@ -522,6 +525,7 @@ implementation
                      else
                      else
                        rg.ungetregisterint(list,l.register);
                        rg.ungetregisterint(list,l.register);
                    end;
                    end;
+{$endif}
                end;
                end;
            end;
            end;
            if (l.loc <> LOC_CREGISTER) or
            if (l.loc <> LOC_CREGISTER) or
@@ -2026,7 +2030,13 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.131  2003-07-23 11:04:15  jonas
+  Revision 1.132  2003-08-03 14:09:50  daniel
+    * Fixed a register allocator bug
+    * Figured out why -dnewra generates superfluous "mov reg1,reg2"
+      statements: changes in location_force. These moves are now no longer
+      constrained so they are optimized away.
+
+  Revision 1.131  2003/07/23 11:04:15  jonas
     * split en_exit_code into a part that may allocate a register and a part
     * split en_exit_code into a part that may allocate a register and a part
       that doesn't, so the former can be done before the register colouring
       that doesn't, so the former can be done before the register colouring
       has been performed
       has been performed

+ 12 - 2
compiler/rgobj.pas

@@ -1861,8 +1861,12 @@ unit rgobj;
             t:=adj^[i];
             t:=adj^[i];
             if (pos(t,selectstack) or pos(t,coalescednodes))=0 then
             if (pos(t,selectstack) or pos(t,coalescednodes))=0 then
               begin
               begin
-                decrement_degree(Tsuperregister(t));
                 add_edge(Tsuperregister(t),u);
                 add_edge(Tsuperregister(t),u);
+                {Do not call decrement_degree because it might move nodes between
+                 lists while the degree does not change (add_edge will increase it).
+                 Instead, we will decrement manually.}
+                if degree[Tsuperregister(t)]>0 then
+                  dec(degree[Tsuperregister(t)]);
               end;
               end;
           end;
           end;
       p:=pos(char(u),freezeworklist);
       p:=pos(char(u),freezeworklist);
@@ -2538,7 +2542,13 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.61  2003-07-21 13:32:39  jonas
+  Revision 1.62  2003-08-03 14:09:50  daniel
+    * Fixed a register allocator bug
+    * Figured out why -dnewra generates superfluous "mov reg1,reg2"
+      statements: changes in location_force. These moves are now no longer
+      constrained so they are optimized away.
+
+  Revision 1.61  2003/07/21 13:32:39  jonas
     * add_edges_used() is now also called for registers allocated with
     * add_edges_used() is now also called for registers allocated with
       getexplicitregisterint()
       getexplicitregisterint()
     * writing the intereference graph is now only done with -dradebug2 and
     * writing the intereference graph is now only done with -dradebug2 and