Browse Source

* optimizer works again with 1.0.x
* fixed wrong loop in FindRegWithConst

peter 21 years ago
parent
commit
19b2170ee4
3 changed files with 57 additions and 43 deletions
  1. 5 4
      compiler/fpcdefs.inc
  2. 18 13
      compiler/i386/csopt386.pas
  3. 34 26
      compiler/i386/daopt386.pas

+ 5 - 4
compiler/fpcdefs.inc

@@ -45,9 +45,6 @@
   {$endif}
   {$define x86}
   {$define cpuextended}
-  {$ifdef VER1_0}
-    {$define NOOPT}
-  {$endif VER1_0}
 {$endif i386}
 
 {$ifdef x86_64}
@@ -88,7 +85,11 @@
 
 {
   $Log$
-  Revision 1.27  2003-11-22 13:11:10  jonas
+  Revision 1.28  2003-12-14 14:18:59  peter
+    * optimizer works again with 1.0.x
+    * fixed wrong loop in FindRegWithConst
+
+  Revision 1.27  2003/11/22 13:11:10  jonas
     - disable the optimizer if compiling with 1.0, because it has a code
       generator (not optimizer) bug that causes crashes in the 1.1
       optimizer

+ 18 - 13
compiler/i386/csopt386.pas

@@ -1354,15 +1354,10 @@ var
 {$ifdef testing}
     hp: tai;
 {$endif testing}
-    tmpresult: boolean;
 begin
+  Result:=false;
   Counter := RS_EAX;
   repeat
-     tmpresult := (ptaiprop(p.optinfo)^.regs[counter].typ in
-         [con_const,con_noRemoveConst]) and
-       (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).opsize = size) and
-       (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[0]^.typ = top_const) and
-       (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[0]^.val = l);
 {$ifdef testing}
      if (ptaiprop(p.optinfo)^.regs[counter].typ in [con_const,con_noRemoveConst]) then
        begin
@@ -1375,11 +1370,17 @@ begin
            hp.previous^.next := hp;
        end;
 {$endif testing}
+     if (ptaiprop(p.optinfo)^.regs[counter].typ in [con_const,con_noRemoveConst]) and
+        (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).opsize = size) and
+        (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[0]^.typ = top_const) and
+        (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[0]^.val = l) then
+       begin
+         res:=taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[1]^.reg;
+         result:=true;
+         exit;
+       end;
      inc(counter);
-  until tmpresult or (Counter > RS_EDI);
-  if tmpResult then
-    res := taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[1]^.reg;
-  FindRegWithConst := tmpResult;
+  until (Counter > RS_EDI);
 end;
 
 
@@ -1561,7 +1562,7 @@ begin
 {$warning add cycle detection for register loads and use xchg if necessary}
                     insertpos := regloads[reginfo.new2oldreg[regcounter]];
                   end;
-  
+
                 hp := Tai_Marker.Create(NoPropInfoStart);
                 InsertLLItem(asml, insertpos.previous,insertpos, hp);
                 hp2 := taicpu.Op_Reg_Reg(A_MOV, S_L,
@@ -1626,7 +1627,7 @@ begin
   hp := Tai_Marker.Create(NoPropInfoStart);
   InsertLLItem(asml, p.previous,p, hp);
   { duplicate the original instruction and replace it's designated operant with the register }
-  hp := p.getcopy;
+  hp := tai(p.getcopy);
   taicpu(hp).loadreg(opnr,reg);
   { add optimizer state info }
   new(ptaiprop(hp.optinfo));
@@ -2055,7 +2056,11 @@ end.
 
 {
   $Log$
-  Revision 1.54  2003-12-13 15:48:47  jonas
+  Revision 1.55  2003-12-14 14:18:59  peter
+    * optimizer works again with 1.0.x
+    * fixed wrong loop in FindRegWithConst
+
+  Revision 1.54  2003/12/13 15:48:47  jonas
     * isgp32reg was being called with both tsuperregister and tregister
       parameters, so changed type to tsuperregister (fixes bug reported by
       Bas Steendijk)

+ 34 - 26
compiler/i386/daopt386.pas

@@ -451,7 +451,7 @@ begin
             (tasmlabel(taicpu(p).oper[0]^.sym) = aktexit2label)) and
         getLastInstruction(p, p) and
         not(regInInstruction(supreg, p)) do
-    hp1 := p; 
+    hp1 := p;
 }
   { don't insert a dealloc for registers which contain the function result }
   { if they are followed by a jump to the exit label (for exit(...))       }
@@ -1957,6 +1957,7 @@ var
   hp1, hp2: tai;
 {$ifdef i386}
   regcounter: tregister;
+  supreg : tsuperregister;
 {$endif i386}
   usedregs, nodeallocregs: tregset;
 begin
@@ -2003,30 +2004,33 @@ begin
             labeltable^[tai_label(p).l.labelnr-lolab].taiobj := p;
 {$ifdef i386}
         ait_regalloc:
-          if tai_regalloc(p).allocation then
-            begin
-              if not(getsupreg(tai_regalloc(p).reg) in usedregs) then
-                include(usedregs, getsupreg(tai_regalloc(p).reg))
-              else
-                addregdeallocfor(list, tai_regalloc(p).reg, p);
-            end
-          else
-            begin
-              exclude(usedregs, getsupreg(tai_regalloc(p).reg));
-              hp1 := p;
-              hp2 := nil;
-              while not(findregalloc(tai_regalloc(p).reg, tai(hp1.next),true)) and
-                    getnextinstruction(hp1, hp1) and
-                    regininstruction(getsupreg(tai_regalloc(p).reg), hp1) Do
-                hp2 := hp1;
-              if hp2 <> nil then
-                begin
-                  hp1 := tai(p.previous);
-                  list.remove(p);
-                  insertllitem(list, hp2, tai(hp2.next), p);
-                  p := hp1;
-                end;
-            end;
+          begin
+            supreg:=getsupreg(tai_regalloc(p).reg);
+            if tai_regalloc(p).allocation then
+              begin
+                if not(supreg in usedregs) then
+                  include(usedregs, supreg)
+                else
+                  addregdeallocfor(list, tai_regalloc(p).reg, p);
+              end
+            else
+              begin
+                exclude(usedregs, supreg);
+                hp1 := p;
+                hp2 := nil;
+                while not(findregalloc(tai_regalloc(p).reg, tai(hp1.next),true)) and
+                      getnextinstruction(hp1, hp1) and
+                      regininstruction(getsupreg(tai_regalloc(p).reg), hp1) Do
+                  hp2 := hp1;
+                if hp2 <> nil then
+                  begin
+                    hp1 := tai(p.previous);
+                    list.remove(p);
+                    insertllitem(list, hp2, tai(hp2.next), p);
+                    p := hp1;
+                  end;
+              end;
+           end;
 {$endif i386}
       end;
       repeat
@@ -2701,7 +2705,11 @@ end.
 
 {
   $Log$
-  Revision 1.57  2003-12-13 15:48:47  jonas
+  Revision 1.58  2003-12-14 14:18:59  peter
+    * optimizer works again with 1.0.x
+    * fixed wrong loop in FindRegWithConst
+
+  Revision 1.57  2003/12/13 15:48:47  jonas
     * isgp32reg was being called with both tsuperregister and tregister
       parameters, so changed type to tsuperregister (fixes bug reported by
       Bas Steendijk)