Browse Source

+ change "mov reg1,reg2;imul x,reg2" to "imul x,reg1,reg2" in popt386
(-dnewoptimizations)
* shl(d) and shr(d) are considered to have a hardcoded register if
they use cl as shift count (since you can't replace them with
another register) in csopt386 (also for -dnewoptimizations)

Jonas Maebe 25 years ago
parent
commit
0cbad4fe45
2 changed files with 64 additions and 23 deletions
  1. 32 21
      compiler/csopt386.pas
  2. 32 2
      compiler/popt386.pas

+ 32 - 21
compiler/csopt386.pas

@@ -509,11 +509,14 @@ begin
 {$endif replaceregdebug}
 {$endif replaceregdebug}
 end;
 end;
 
 
-function NoHardCodedRegs(p: paicpu): boolean;
+function NoHardCodedRegs(p: paicpu; orgReg, newReg: tRegister): boolean;
 var chCount: byte;
 var chCount: byte;
 begin
 begin
   case p^.opcode of
   case p^.opcode of
     A_IMUL: noHardCodedRegs := p^.ops <> 1;
     A_IMUL: noHardCodedRegs := p^.ops <> 1;
+    A_SHL,A_SHR,A_SHLD,A_SHRD: noHardCodedRegs :=
+      (p^.oper[0].typ <> top_reg) or
+      ((orgReg <> R_ECX) and (newReg <> R_ECX));
     else
     else
       begin
       begin
         NoHardCodedRegs := true;
         NoHardCodedRegs := true;
@@ -716,7 +719,7 @@ begin
          Not (PPaiProp(endP^.optInfo)^.canBeRemoved) then
          Not (PPaiProp(endP^.optInfo)^.canBeRemoved) then
         begin
         begin
           sequenceEnd :=
           sequenceEnd :=
-            noHardCodedRegs(paicpu(endP)) and
+            noHardCodedRegs(paicpu(endP),orgReg,newReg) and
             RegLoadedWithNewValue(newReg,true,paicpu(endP)) or
             RegLoadedWithNewValue(newReg,true,paicpu(endP)) or
             (GetNextInstruction(endp,hp) and
             (GetNextInstruction(endp,hp) and
              FindRegDealloc(newReg,hp));
              FindRegDealloc(newReg,hp));
@@ -739,7 +742,7 @@ begin
             (orgRegCanBeModified or not(newRegModified)) and
             (orgRegCanBeModified or not(newRegModified)) and
             (endP^.typ = ait_instruction) and
             (endP^.typ = ait_instruction) and
             not(paicpu(endP)^.is_jmp) and
             not(paicpu(endP)^.is_jmp) and
-            NoHardCodedRegs(paicpu(endP)) and
+            NoHardCodedRegs(paicpu(endP),orgReg,newReg) and
             RegSizesOk(orgReg,newReg,paicpu(endP)) and
             RegSizesOk(orgReg,newReg,paicpu(endP)) and
             not RegModifiedByInstruction(orgReg,endP);
             not RegModifiedByInstruction(orgReg,endP);
         end;
         end;
@@ -747,7 +750,7 @@ begin
   sequenceEnd := sequenceEnd and
   sequenceEnd := sequenceEnd and
      (not(assigned(endp)) or
      (not(assigned(endp)) or
       not(endp^.typ = ait_instruction) or
       not(endp^.typ = ait_instruction) or
-      (noHardCodedRegs(paicpu(endP)) and
+      (noHardCodedRegs(paicpu(endP),orgReg,newReg) and
        RegSizesOk(orgReg,newReg,paicpu(endP)) and
        RegSizesOk(orgReg,newReg,paicpu(endP)) and
        not(newRegModified and
        not(newRegModified and
            (orgReg in PPaiProp(endP^.optInfo)^.usedRegs) and
            (orgReg in PPaiProp(endP^.optInfo)^.usedRegs) and
@@ -1142,31 +1145,33 @@ Begin
 End;
 End;
 
 
 Procedure RemoveInstructs(AsmL: PAasmOutput; First, Last: Pai);
 Procedure RemoveInstructs(AsmL: PAasmOutput; First, Last: Pai);
-{Removes the marked instructions and disposes the PPaiProps of the other
- instructions, restoring their line number}
+{ Removes the marked instructions and disposes the PPaiProps of the other }
+{ instructions                                                            }
 Var p, hp1: Pai;
 Var p, hp1: Pai;
-{$IfDef TP}
-    TmpLine: Longint;
-{$EndIf TP}
-    InstrCnt: Longint;
-Begin
+begin
   p := First;
   p := First;
-  SkipHead(P);
-  InstrCnt := 1;
   While (p <> Last) Do
   While (p <> Last) Do
     Begin
     Begin
+      If (p^.typ = ait_marker) and
+         (pai_marker(p)^.kind in [noPropInfoStart,noPropInfoEnd]) then
+        begin
+          hp1 := pai(p^.next);
+          asmL^.remove(p);
+          dispose(p,done);
+          p := hp1
+        end
+      else
 {$ifndef noinstremove}
 {$ifndef noinstremove}
-      If PPaiProp(p^.OptInfo)^.CanBeRemoved
-        Then
-          Begin
+        if assigned(p^.optInfo) and
+              PPaiProp(p^.optInfo)^.canBeRemoved then
+          begin
 {$IfDef TP}
 {$IfDef TP}
             Dispose(PPaiProp(p^.OptInfo));
             Dispose(PPaiProp(p^.OptInfo));
 {$EndIf}
 {$EndIf}
-            GetNextInstruction(p, hp1);
+            hp1 := pai(p^.next);
             AsmL^.Remove(p);
             AsmL^.Remove(p);
             Dispose(p, Done);
             Dispose(p, Done);
             p := hp1;
             p := hp1;
-            Inc(InstrCnt);
           End
           End
         Else
         Else
 {$endif noinstremove}
 {$endif noinstremove}
@@ -1175,8 +1180,7 @@ Begin
             Dispose(PPaiProp(p^.OptInfo));
             Dispose(PPaiProp(p^.OptInfo));
 {$EndIf TP}
 {$EndIf TP}
             p^.OptInfo := nil;
             p^.OptInfo := nil;
-            GetNextInstruction(p, p);
-            Inc(InstrCnt);
+            p := pai(p^.next);;
           End;
           End;
     End;
     End;
 {$IfNDef TP}
 {$IfNDef TP}
@@ -1194,7 +1198,14 @@ End.
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.49  2000-02-12 10:54:18  jonas
+ Revision 1.50  2000-02-12 14:10:14  jonas
+   + change "mov reg1,reg2;imul x,reg2" to "imul x,reg1,reg2" in popt386
+     (-dnewoptimizations)
+   * shl(d) and shr(d) are considered to have a hardcoded register if
+     they use cl as shift count (since you can't replace them with
+     another register) in csopt386 (also for -dnewoptimizations)
+
+ Revision 1.49  2000/02/12 10:54:18  jonas
    * fixed edi allocation in allocRegBetween
    * fixed edi allocation in allocRegBetween
    * fixed bug I introduced yesterday, added comment to prevent it from
    * fixed bug I introduced yesterday, added comment to prevent it from
      happening again in the future
      happening again in the future

+ 32 - 2
compiler/popt386.pas

@@ -44,7 +44,7 @@ Uses
 {$ifdef finaldestdebug}
 {$ifdef finaldestdebug}
   cobjects,
   cobjects,
 {$endif finaldestdebug}
 {$endif finaldestdebug}
-  cpubase,cpuasm,DAOpt386;
+  cpubase,cpuasm,DAOpt386,cobjects;
 
 
 Function RegUsedAfterInstruction(Reg: TRegister; p: Pai; Var UsedRegs: TRegSet): Boolean;
 Function RegUsedAfterInstruction(Reg: TRegister; p: Pai; Var UsedRegs: TRegSet): Boolean;
 Begin
 Begin
@@ -1738,6 +1738,29 @@ Begin
               A_FSTP,A_FISTP:
               A_FSTP,A_FISTP:
                 if doFpuLoadStoreOpt(asmL,p) then
                 if doFpuLoadStoreOpt(asmL,p) then
                   continue;
                   continue;
+{$ifdef foldArithOps}
+              A_IMUL:
+                begin
+                  if (paicpu(p)^.oper[1].typ = top_reg) and
+                     ((paicpu(p)^.oper[2].typ = top_none) or
+                      ((paicpu(p)^.oper[2].typ = top_reg) and
+                       (paicpu(p)^.oper[2].reg = paicpu(p)^.oper[1].reg))) and
+                     getLastInstruction(p,hp1) and
+                     (hp1^.typ = ait_instruction) and
+                     (paicpu(hp1)^.opcode = A_MOV) and
+                     (paicpu(hp1)^.oper[0].typ = top_reg) and
+                     (paicpu(hp1)^.oper[1].typ = top_reg) and
+                     (paicpu(hp1)^.oper[1].reg = paicpu(p)^.oper[1].reg) then
+              { change "mov reg1,reg2; imul y,reg2" to "imul y,reg1,reg2" }
+                    begin
+                      paicpu(p)^.ops := 3;
+                      paicpu(p)^.loadreg(1,paicpu(hp1)^.oper[0].reg);
+                      paicpu(p)^.loadreg(2,paicpu(hp1)^.oper[1].reg);
+                      asmL^.remove(hp1);
+                      dispose(hp1,done);
+                    end;
+                end;
+{$endif foldArithOps}
               A_MOV:
               A_MOV:
                 Begin
                 Begin
                   If (Paicpu(p)^.oper[0].typ = top_reg) And
                   If (Paicpu(p)^.oper[0].typ = top_reg) And
@@ -1865,7 +1888,14 @@ End.
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.84  2000-02-09 13:22:58  peter
+ Revision 1.85  2000-02-12 14:10:15  jonas
+   + change "mov reg1,reg2;imul x,reg2" to "imul x,reg1,reg2" in popt386
+     (-dnewoptimizations)
+   * shl(d) and shr(d) are considered to have a hardcoded register if
+     they use cl as shift count (since you can't replace them with
+     another register) in csopt386 (also for -dnewoptimizations)
+
+ Revision 1.84  2000/02/09 13:22:58  peter
    * log truncated
    * log truncated
 
 
  Revision 1.83  2000/02/04 13:53:04  jonas
  Revision 1.83  2000/02/04 13:53:04  jonas