Browse Source

+ support for optimizing simple sequences with div/idiv/mul opcodes

Jonas Maebe 25 years ago
parent
commit
3974b23c97
2 changed files with 49 additions and 22 deletions
  1. 39 19
      compiler/i386/csopt386.pas
  2. 10 3
      compiler/i386/daopt386.pas

+ 39 - 19
compiler/i386/csopt386.pas

@@ -1285,6 +1285,18 @@ begin
         ppaiprop(startMod^.optInfo)^.canBeRemoved := true;
 end;
 
+function is_mov_for_div(p: paicpu): boolean;
+begin
+  is_mov_for_div :=
+    (p^.opcode = A_MOV) and
+    (p^.oper[0].typ = top_const) and
+    (p^.oper[1].typ = top_reg) and
+    (p^.oper[1].reg = R_EDX) and
+    getNextInstruction(p,p) and
+    (p^.typ = ait_instruction) and
+    ((p^.opcode = A_DIV) or
+     (p^.opcode = A_IDIV));
+end;
 
 procedure DoCSE(AsmL: PAasmOutput; First, Last: Pai; findPrevSeqs, doSubOpts: boolean);
 {marks the instructions that can be removed by RemoveInstructs. They're not
@@ -1367,26 +1379,31 @@ Begin
                                                (paicpu(p)^.opcode = A_MOVZX) or
                                                (paicpu(p)^.opcode = A_MOVSX)) And
                                               (paicpu(p)^.oper[1].typ = top_reg) then
-                                             begin
-                                               regCounter := reg32(paicpu(p)^.oper[1].reg);
-                                               if (regCounter in reginfo.regsStillUsedAfterSeq) then
-                                                 begin
-                                                   if (hp1 = nil) then
-                                                     hp1 := reginfo.lastReload[regCounter];
-                                                 end
+                                             if not is_mov_for_div(paicpu(p)) then
+                                               begin
+                                                 regCounter := reg32(paicpu(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 := ppaiprop(p^.optinfo)^.regs[regCounter].nrofmods downto 1 do
-                                                     begin
-                                                       if regModifiedByInstruction(regCounter,hp5) then
-                                                         PPaiProp(hp5^.OptInfo)^.CanBeRemoved := True;
-                                                       getNextInstruction(hp5,hp5);
-                                                     end;
-                                                 end
+                                                 else
+                                                   begin
+                                                     hp5 := p;
+                                                     for cnt3 := ppaiprop(p^.optinfo)^.regs[regCounter].nrofmods downto 1 do
+                                                       begin
+                                                         if regModifiedByInstruction(regCounter,hp5) then
+                                                           PPaiProp(hp5^.OptInfo)^.CanBeRemoved := True;
+                                                         getNextInstruction(hp5,hp5);
+                                                       end;
+                                                   end
+{$endif noremove}
+                                               end
+{$ifndef noremove}
+                                             else
+                                               PPaiProp(p^.OptInfo)^.CanBeRemoved := True
 {$endif noremove}
-                                             end
                                          end
 {$ifndef noremove}
                                        else
@@ -1684,7 +1701,10 @@ End.
 
 {
   $Log$
-  Revision 1.6  2000-11-14 12:17:34  jonas
+  Revision 1.7  2000-11-28 16:32:11  jonas
+    + support for optimizing simple sequences with div/idiv/mul opcodes
+
+  Revision 1.6  2000/11/14 12:17:34  jonas
     * fixed some bugs in checksequence
 
   Revision 1.5  2000/11/09 12:34:44  jonas

+ 10 - 3
compiler/i386/daopt386.pas

@@ -2219,7 +2219,9 @@ Begin
                   hp := new(pai_asm_comment,init(strpnew('destroying eax and edx')));
                   insertllitem(asml,p,p^.next,hp);
 {$endif statedebug}
-                  DestroyReg(CurProp, R_EAX, true);
+{                  DestroyReg(CurProp, R_EAX, true);}
+                  AddInstr2RegContents({$ifdef statedebug}asml,{$endif}
+                    paicpu(p), R_EAX);
                   DestroyReg(CurProp, R_EDX, true)
                 End;
               A_IMUL:
@@ -2234,7 +2236,9 @@ Begin
                         hp := new(pai_asm_comment,init(strpnew('destroying eax and edx')));
                         insertllitem(asml,p,p^.next,hp);
 {$endif statedebug}
-                        DestroyReg(CurProp, R_EAX, true);
+{                        DestroyReg(CurProp, R_EAX, true); }
+                        AddInstr2RegContents({$ifdef statedebug}asml,{$endif}
+                          paicpu(p), R_EAX);
                         DestroyReg(CurProp, R_EDX, true)
                       End
                     Else
@@ -2443,7 +2447,10 @@ End.
 
 {
   $Log$
-  Revision 1.9  2000-11-23 14:20:18  jonas
+  Revision 1.10  2000-11-28 16:32:11  jonas
+    + support for optimizing simple sequences with div/idiv/mul opcodes
+
+  Revision 1.9  2000/11/23 14:20:18  jonas
     * fixed stupid bug in previous commit
 
   Revision 1.8  2000/11/23 13:26:33  jonas