Browse Source

* fixed some more bugs which only showed up in a ppc cross compiler

Jonas Maebe 21 years ago
parent
commit
f3d82160b1
3 changed files with 64 additions and 99 deletions
  1. 47 94
      compiler/i386/csopt386.pas
  2. 6 1
      compiler/i386/daopt386.pas
  3. 11 4
      compiler/i386/rropt386.pas

+ 47 - 94
compiler/i386/csopt386.pas

@@ -1189,16 +1189,16 @@ begin
           removeLast := storeBack(endP, orgsupreg, newsupreg);
           removeLast := storeBack(endP, orgsupreg, newsupreg);
           sequenceEnd :=
           sequenceEnd :=
             { no support for (i)div, mul and imul with hardcoded operands }
             { no support for (i)div, mul and imul with hardcoded operands }
-            (noHardCodedRegs(taicpu(endP),orgsupreg,newsupreg) and
+            noHardCodedRegs(taicpu(endP),orgsupreg,newsupreg) and
             { if newsupreg gets loaded with a new value, we can stop   }
             { if newsupreg gets loaded with a new value, we can stop   }
             { replacing newsupreg with oldReg here (possibly keeping   }
             { replacing newsupreg with oldReg here (possibly keeping   }
             { the original contents of oldReg so we still know them }
             { the original contents of oldReg so we still know them }
             { afterwards)                                           }
             { afterwards)                                           }
-             RegLoadedWithNewValue(newsupreg,true,taicpu(endP)) or
+             (RegLoadedWithNewValue(newsupreg,true,taicpu(endP)) or
             { we can also stop if we reached the end of the use of }
             { we can also stop if we reached the end of the use of }
             { newReg's current contents                            }
             { newReg's current contents                            }
-             (GetNextInstruction(endp,hp) and
-              FindRegDealloc(newsupreg,hp)));
+              (GetNextInstruction(endp,hp) and
+               FindRegDealloc(newsupreg,hp)));
           { to be able to remove the first and last instruction of  }
           { to be able to remove the first and last instruction of  }
           {   movl %reg1, %reg2                                     }
           {   movl %reg1, %reg2                                     }
           {   <operations on %reg2> (replacing reg2 with reg1 here) }
           {   <operations on %reg2> (replacing reg2 with reg1 here) }
@@ -1612,6 +1612,30 @@ begin
 end;
 end;
 
 
 
 
+procedure replaceoperandwithreg(asml: taasmoutput; p: tai; opnr: byte; reg: tregister);
+var
+  hp: tai;
+begin
+  { new instruction -> it's info block is not in the big one allocated at the start }
+  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;
+  taicpu(hp).loadreg(opnr,reg);
+  { add optimizer state info }
+  new(ptaiprop(hp.optinfo));
+  ptaiprop(hp.optinfo)^ := ptaiprop(p.optinfo)^;
+  { new instruction can not be removed }
+  ptaiprop(hp.optinfo)^.canBeRemoved := false;
+  { but the old one can }
+  ptaiprop(p.optinfo)^.canBeRemoved := true;
+  { insert end marker }
+  InsertLLItem(asml, p.previous, p, hp);
+  hp := Tai_Marker.Create(NoPropInfoEnd);
+  InsertLLItem(asml, p.previous, p, hp);
+end;
+
+
 procedure doCSE(asml: TAAsmOutput; First, Last: tai; findPrevSeqs, doSubOpts: boolean);
 procedure doCSE(asml: TAAsmOutput; First, Last: tai; findPrevSeqs, doSubOpts: boolean);
 {marks the instructions that can be removed by RemoveInstructs. They're not
 {marks the instructions that can be removed by RemoveInstructs. They're not
  removed immediately because sometimes an instruction needs to be checked in
  removed immediately because sometimes an instruction needs to be checked in
@@ -1692,44 +1716,7 @@ begin
                                    Cnt2 := 1;
                                    Cnt2 := 1;
                                    while Cnt2 <= Cnt do
                                    while Cnt2 <= Cnt do
                                      begin
                                      begin
-(*
-                                       if not(regInInstruction(getsupreg(taicpu(hp2).oper[1]^.reg), p)) and
-                                          not(ptaiprop(p.optinfo)^.canBeRemoved) then
-                                         begin
-                                           if (p.typ = ait_instruction) and
-                                              ((taicpu(p).OpCode = A_MOV)  or
-                                               (taicpu(p).opcode = A_MOVZX) or
-                                               (taicpu(p).opcode = A_MOVSX)) and
-                                              (taicpu(p).oper[1]^.typ = top_reg) then
-                                             if not is_mov_for_div(taicpu(p)) then
-                                               begin
-                                                 regCounter := getsupreg(taicpu(p).oper[1]^.reg);
-                                                 if (regCounter in reginfo.regsStillUsedAfterSeq) then
-                                                   begin
-                                                    if (hp1 = nil) then
-                                                      hp1 := reginfo.lastReload[regCounter];
-                                                   end
-{$ifndef noremove}
-                                                 else
-                                                   begin
-                                                     hp5 := p;
-                                                     for cnt3 := ptaiprop(p.optinfo)^.regs[regCounter].nrofmods downto 1 do
-                                                       begin
-                                                         if regModifiedByInstruction(regCounter,hp5) then
-                                                           ptaiprop(hp5.optinfo)^.CanBeRemoved := True;
-                                                         getNextInstruction(hp5,hp5);
-                                                       end;
-                                                   end
-{$endif noremove}
-                                               end
-{$ifndef noremove}
-                                             else
-                                               ptaiprop(p.optinfo)^.CanBeRemoved := True
-{$endif noremove}
-                                         end
-*)
 {$ifndef noremove}
 {$ifndef noremove}
-(*                                       else *)
                                          ptaiprop(p.optinfo)^.CanBeRemoved := True
                                          ptaiprop(p.optinfo)^.CanBeRemoved := True
 {$endif noremove}
 {$endif noremove}
                                        ; inc(Cnt2);
                                        ; inc(Cnt2);
@@ -1739,56 +1726,19 @@ begin
                                    GetLastInstruction(hp2, hp4);
                                    GetLastInstruction(hp2, hp4);
 
 
 {$IfDef CSDebug}
 {$IfDef CSDebug}
-              for regcounter := RS_EAX To RS_EDI do
-                if (regcounter in reginfo.RegsLoadedforRef) then
-                  begin
-           hp5 := tai_comment.Create(strpnew('New: '+std_reg2str[regcounter]+', Old: '+
-                                                  std_reg2str[reginfo.new2oldreg[regcounter]])));
-           InsertLLItem(asml, tai(hp2.previous), hp2, hp5);
-                  end;
+                                   for regcounter := RS_EAX To RS_EDI do
+                                     if (regcounter in reginfo.RegsLoadedforRef) then
+                                       begin
+                                         hp5 := tai_comment.Create(strpnew('New: '+std_reg2str[regcounter]+', Old: '+
+                                           std_reg2str[reginfo.new2oldreg[regcounter]])));
+                                         InsertLLItem(asml, tai(hp2.previous), hp2, hp5);
+                                       end;
 {$EndIf CSDebug}
 {$EndIf CSDebug}
  { if some registers were different in the old and the new sequence, move }
  { if some registers were different in the old and the new sequence, move }
  { the contents of those old registers to the new ones                    }
  { the contents of those old registers to the new ones                    }
                                    loadcseregs(asml,reginfo,p,prevseq,hp2,hp4,cnt);
                                    loadcseregs(asml,reginfo,p,prevseq,hp2,hp4,cnt);
                                    continue;
                                    continue;
                                  end
                                  end
-(*
-                               else
-                                 if (ptaiprop(p.optinfo)^.
-                                      regs[getsupreg(taicpu(p).oper[1]^.reg)].typ
-                                        in [con_ref,con_noRemoveRef]) and
-                                    (ptaiprop(p.optinfo)^.CanBeRemoved) then
-                                   if (cnt > 0) then
-                                     begin
-                                       p := hp2;
-                                       Cnt2 := 1;
-                                       while Cnt2 <= Cnt do
-                                         begin
-                                           if RegInInstruction(getsupregtaicpu(hp2).oper[1]^.reg), p) then
-                                             ptaiprop(p.optinfo)^.CanBeRemoved := False;
-                                           inc(Cnt2);
-                                           GetNextInstruction(p, p);
-                                         end;
-                                       Continue;
-                                     end
-                                   else
-                                     begin
-                                       { Fix for web bug 972 }
-                                       regCounter := getsupreg(taicpu(p).oper[1]^.reg);
-                                       cnt := ptaiprop(p.optinfo)^.Regs[regCounter].nrofMods;
-                                       hp3 := p;
-                                       for cnt2 := 1 to cnt do
-                                         if not(regModifiedByInstruction(regCounter,hp3) and
-                                                not(ptaiprop(hp3.optinfo)^.canBeRemoved)) then
-                                           getNextInstruction(hp3,hp3)
-                                         else
-                                           break;
-                                       getLastInstruction(p,hp4);
-                                       RestoreRegContentsTo(regCounter,
-                                         ptaiprop(hp4.optinfo)^.Regs[regCounter],
-                                         p,hp3);
-                                     end;
-*)
                               end;
                               end;
                           end;
                           end;
                       { try to replace the new reg with the old reg }
                       { try to replace the new reg with the old reg }
@@ -1812,9 +1762,9 @@ begin
                           end
                           end
                         else
                         else
                           begin
                           begin
-                            if (taicpu(p).oper[1]^.typ = top_reg) and
-                               not regInOp(getsupreg(taicpu(p).oper[1]^.reg),taicpu(p).oper[0]^) then
-                             removePrevNotUsedLoad(p,getsupreg(taicpu(p).oper[1]^.reg),false);
+                             if (taicpu(p).oper[1]^.typ = top_reg) and
+                                not regInOp(getsupreg(taicpu(p).oper[1]^.reg),taicpu(p).oper[0]^) then
+                               removePrevNotUsedLoad(p,getsupreg(taicpu(p).oper[1]^.reg),false);
                              if doSubOpts and
                              if doSubOpts and
                                 (taicpu(p).opcode <> A_LEA) and
                                 (taicpu(p).opcode <> A_LEA) and
                                 (taicpu(p).oper[0]^.typ = top_ref) then
                                 (taicpu(p).oper[0]^.typ = top_ref) then
@@ -1832,7 +1782,7 @@ begin
                                     end
                                     end
                                   else
                                   else
                                     begin
                                     begin
-                                      taicpu(p).loadreg(0,memreg);
+                                      replaceoperandwithreg(asml,p,0,memreg);
                                       allocregbetween(asml,memreg,hp5,p);
                                       allocregbetween(asml,memreg,hp5,p);
                                       regcounter := getsupreg(memreg);
                                       regcounter := getsupreg(memreg);
                                       incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
                                       incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
@@ -1910,7 +1860,7 @@ begin
                                 taicpu(p).oper[0]^.ref^,hp5);
                                 taicpu(p).oper[0]^.ref^,hp5);
                               if memreg <> NR_NO then
                               if memreg <> NR_NO then
                                 begin
                                 begin
-                                  taicpu(p).loadreg(0,memreg);
+                                  replaceoperandwithreg(asml,p,0,memreg);
                                   allocregbetween(asml,memreg,hp5,p);
                                   allocregbetween(asml,memreg,hp5,p);
                                   regcounter := getsupreg(memreg);
                                   regcounter := getsupreg(memreg);
                                   incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
                                   incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
@@ -1941,7 +1891,7 @@ begin
                                   updatestate(regcounter,hp1);
                                   updatestate(regcounter,hp1);
                                   hp1 := Tai_Marker.Create(NoPropInfoStart);
                                   hp1 := Tai_Marker.Create(NoPropInfoStart);
                                   insertllitem(asml,p,p.next,hp1);
                                   insertllitem(asml,p,p.next,hp1);
-                                  taicpu(p).loadreg(0,memreg);
+                                  replaceoperandwithreg(asml,p,0,memreg);
                                   allocregbetween(asml,memreg,hp5,
                                   allocregbetween(asml,memreg,hp5,
                                     tai(p.next.next));
                                     tai(p.next.next));
                                 end;
                                 end;
@@ -1956,7 +1906,7 @@ begin
                                 taicpu(p).oper[1]^.ref^,hp5);
                                 taicpu(p).oper[1]^.ref^,hp5);
                               if memreg <> NR_NO then
                               if memreg <> NR_NO then
                                 begin
                                 begin
-                                  taicpu(p).loadreg(1,memreg);
+                                  replaceoperandwithreg(asml,p,1,memreg);
                                   allocregbetween(asml,memreg,hp5,p);
                                   allocregbetween(asml,memreg,hp5,p);
                                   regcounter := getsupreg(memreg);
                                   regcounter := getsupreg(memreg);
                                   incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
                                   incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
@@ -1993,7 +1943,7 @@ begin
                                   updatestate(regcounter,hp1);
                                   updatestate(regcounter,hp1);
                                   hp1 := Tai_Marker.Create(NoPropInfoStart);
                                   hp1 := Tai_Marker.Create(NoPropInfoStart);
                                   insertllitem(asml,p,p.next,hp1);
                                   insertllitem(asml,p,p.next,hp1);
-                                  taicpu(p).loadreg(1,memreg);
+                                  replaceoperandwithreg(asml,p,1,memreg);
                                   allocregbetween(asml,memreg,hp5,
                                   allocregbetween(asml,memreg,hp5,
                                     tai(p.next.next));
                                     tai(p.next.next));
                                 end;
                                 end;
@@ -2099,7 +2049,10 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.52  2003-11-28 18:49:05  jonas
+  Revision 1.53  2003-12-07 19:19:56  jonas
+    * fixed some more bugs which only showed up in a ppc cross compiler
+
+  Revision 1.52  2003/11/28 18:49:05  jonas
     * fixed bug which only showed up in the ppc crosscompiler :)
     * fixed bug which only showed up in the ppc crosscompiler :)
 
 
   Revision 1.51  2003/11/22 13:10:32  jonas
   Revision 1.51  2003/11/22 13:10:32  jonas

+ 6 - 1
compiler/i386/daopt386.pas

@@ -843,6 +843,8 @@ var
   Cnt: Byte;
   Cnt: Byte;
 begin
 begin
   TmpResult := False;
   TmpResult := False;
+  if supreg = RS_INVALID then
+    exit;
   if (p1.typ = ait_instruction) then
   if (p1.typ = ait_instruction) then
     case taicpu(p1).opcode of
     case taicpu(p1).opcode of
       A_IMUL:
       A_IMUL:
@@ -2705,7 +2707,10 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.55  2003-11-22 13:10:32  jonas
+  Revision 1.56  2003-12-07 19:19:56  jonas
+    * fixed some more bugs which only showed up in a ppc cross compiler
+
+  Revision 1.55  2003/11/22 13:10:32  jonas
     * fixed double unit usage
     * fixed double unit usage
 
 
   Revision 1.54  2003/11/22 00:40:19  jonas
   Revision 1.54  2003/11/22 00:40:19  jonas

+ 11 - 4
compiler/i386/rropt386.pas

@@ -251,15 +251,19 @@ begin
           if not reg2Modified then
           if not reg2Modified then
             reg2Modified := regModifiedByInstruction(reg2,endP);
             reg2Modified := regModifiedByInstruction(reg2,endP);
 
 
+          tmpResult :=
+            ((not isInstruction) or
+             (NoHardCodedRegs(taicpu(endP),reg1,reg2) and
+              RegSizesOk(reg1,reg2,taicpu(endP))));
+
           if sequenceEnd then
           if sequenceEnd then
             break;
             break;
 
 
           tmpResult :=
           tmpResult :=
+            tmpresult and
             (endp.typ <> ait_label) and
             (endp.typ <> ait_label) and
             ((not isInstruction) or
             ((not isInstruction) or
-             (NoHardCodedRegs(taicpu(endP),reg1,reg2) and
-              RegSizesOk(reg1,reg2,taicpu(endP)) and
-              (taicpu(endp).opcode <> A_JMP)));
+             (taicpu(endp).opcode <> A_JMP));
         end;
         end;
     end;
     end;
 
 
@@ -346,7 +350,10 @@ End.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.23  2003-11-22 00:40:19  jonas
+  Revision 1.24  2003-12-07 19:19:56  jonas
+    * fixed some more bugs which only showed up in a ppc cross compiler
+
+  Revision 1.23  2003/11/22 00:40:19  jonas
     * fixed optimiser so it compiles again
     * fixed optimiser so it compiles again
     * fixed several bugs which were in there already for a long time, but
     * fixed several bugs which were in there already for a long time, but
       which only popped up now :) -O2/-O3 will now optimise less than in
       which only popped up now :) -O2/-O3 will now optimise less than in