Browse Source

* don't remove regalloc/regdealloc pair if it's immediately followed by a
use of the register (can happen if the register is unused afterwards;
remove the alloc/dealloc results in no temp being allocated for the
register, so that instruction becomes invalid)

git-svn-id: branches/jvmbackend@18455 -

Jonas Maebe 14 years ago
parent
commit
a5af71a8d8
1 changed files with 49 additions and 15 deletions
  1. 49 15
      compiler/jvm/rgcpu.pas

+ 49 - 15
compiler/jvm/rgcpu.pas

@@ -139,6 +139,34 @@ implementation
               result:=tai_regalloc(p).reg=reg;
         end;
 
+      function regininstruction(p: tai; reg: tregister): boolean;
+        var
+          sr: tsuperregister;
+          i: longint;
+        begin
+          result:=false;
+          if p.typ<>ait_instruction then
+            exit;
+          sr:=getsupreg(reg);
+          for i:=0 to taicpu(p).ops-1 do
+            case taicpu(p).oper[0]^.typ of
+              top_reg:
+                if (getsupreg(taicpu(p).oper[0]^.reg)=sr) then
+                  exit(true);
+              top_ref:
+                begin
+                  if (getsupreg(taicpu(p).oper[0]^.ref^.base)=sr) then
+                    exit(true);
+                  if (getsupreg(taicpu(p).oper[0]^.ref^.index)=sr) then
+                    exit(true);
+                  if (getsupreg(taicpu(p).oper[0]^.ref^.indexbase)=sr) then
+                    exit(true);
+                  if (getsupreg(taicpu(p).oper[0]^.ref^.indexbase)=sr) then
+                    exit(true);
+                end;
+            end;
+        end;
+
       function try_remove_store_dealloc_load(var p: tai): boolean;
         var
           dealloc,
@@ -174,7 +202,7 @@ implementation
 
 
       var
-        p,next: tai;
+        p,next,nextnext: tai;
         reg: tregister;
         removedsomething: boolean;
       begin
@@ -188,21 +216,27 @@ implementation
                   begin
                     reg:=NR_NO;
                     next:=nextskipping(p,[ait_comment]);
-                    { remove
-                        alloc reg
-                        dealloc reg
-                      (can appear after optimisations, necessary to prevent
-                       useless stack slot allocations) }
-                    if isregallocoftyp(p,ra_alloc,reg) and
-                       isregallocoftyp(next,ra_dealloc,reg) then
+                    nextnext:=nextskipping(next,[ait_comment,ait_regalloc]);
+                    if assigned(nextnext) then
                       begin
-                        list.remove(p);
-                        p.free;
-                        p:=tai(next.next);
-                        list.remove(next);
-                        next.free;
-                        removedsomething:=true;
-                        continue;
+                        { remove
+                            alloc reg
+                            dealloc reg
+
+                          (can appear after optimisations, necessary to prevent
+                           useless stack slot allocations) }
+                        if isregallocoftyp(p,ra_alloc,reg) and
+                           isregallocoftyp(next,ra_dealloc,reg) and
+                           not regininstruction(nextnext,reg) then
+                          begin
+                            list.remove(p);
+                            p.free;
+                            p:=tai(next.next);
+                            list.remove(next);
+                            next.free;
+                            removedsomething:=true;
+                            continue;
+                          end;
                       end;
                   end;
                 ait_instruction: