From a849e51a3c698f59fe89facb9b161b2d8d91bfdb Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 9 Dec 2020 20:57:06 +0000 Subject: [PATCH] + m68k: JSR, RTS to JMP optimization git-svn-id: trunk@47740 - --- compiler/m68k/aoptcpu.pas | 23 ++++++++++++++++++++++- compiler/m68k/cpubase.pas | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/compiler/m68k/aoptcpu.pas b/compiler/m68k/aoptcpu.pas index 680728b579..df93f3611a 100644 --- a/compiler/m68k/aoptcpu.pas +++ b/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, equals to TST , just shorter and TST is more flexible anyway } A_CMP,A_CMPI: if (taicpu(p).oper[0]^.typ = top_const) and diff --git a/compiler/m68k/cpubase.pas b/compiler/m68k/cpubase.pas index d8fb9856e1..72abe345e1 100644 --- a/compiler/m68k/cpubase.pas +++ b/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 *****************************************************************************}