Browse Source

+ m68k: JSR, RTS to JMP optimization

git-svn-id: trunk@47740 -
florian 4 years ago
parent
commit
a849e51a3c
2 changed files with 24 additions and 1 deletions
  1. 22 1
      compiler/m68k/aoptcpu.pas
  2. 2 0
      compiler/m68k/cpubase.pas

+ 22 - 1
compiler/m68k/aoptcpu.pas

@@ -48,7 +48,7 @@ unit aoptcpu;
   Implementation
 
     uses
-      cutils, aasmcpu, cgutils, globals, verbose, cpuinfo, itcpugas;
+      cutils, aasmcpu, cgutils, globtype, globals, verbose, cpuinfo, itcpugas;
 
 { Range check must be disabled explicitly as conversions between signed and unsigned
   32-bit values are done without explicit typecasts }
@@ -88,6 +88,14 @@ unit aoptcpu;
           end
       end;
 
+    function MatchInstruction(const instr: tai; const op: TAsmOp; const opsize: topsizes): boolean;
+      begin
+        result :=
+          (instr.typ = ait_instruction) and
+          (taicpu(instr).opcode = op) and
+          ((opsize = []) or (taicpu(instr).opsize in opsize));
+      end;
+
     function TCpuAsmOptimizer.MaybeRealConstOperSimplify(var p: tai): boolean;
       var
         tmpint64: int64;
@@ -386,6 +394,19 @@ unit aoptcpu;
                     taicpu(p).ops:=2;
                     result:=true;
                   end;
+              A_JSR:
+                begin
+                  if (cs_opt_level4 in current_settings.optimizerswitches) and
+                    GetNextInstruction(p,next) and
+                    MatchInstruction(next,A_RTS,[S_NO]) then
+                    begin
+                      DebugMsg('Optimizer: JSR, RTS to JMP',p);
+                      taicpu(p).opcode:=A_JMP;
+                      asml.remove(next);
+                      next.free;
+                      result:=true;
+                    end;
+                end;
               { CMP #0,<ea> equals to TST <ea>, just shorter and TST is more flexible anyway }
               A_CMP,A_CMPI:
                 if (taicpu(p).oper[0]^.typ = top_const) and

+ 2 - 0
compiler/m68k/cpubase.pas

@@ -158,6 +158,8 @@ unit cpubase;
        { S_FX  = Extended type      }
        topsize = (S_NO,S_B,S_W,S_L,S_FS,S_FD,S_FX,S_IQ);
 
+       TOpSizes = set of topsize;
+
 {*****************************************************************************
                                  Constants
 *****************************************************************************}