diff --git a/compiler/avr/aoptcpu.pas b/compiler/avr/aoptcpu.pas index 0ee8498473..86ed1accbe 100644 --- a/compiler/avr/aoptcpu.pas +++ b/compiler/avr/aoptcpu.pas @@ -444,12 +444,16 @@ Implementation } else if not(cs_opt_level3 in current_settings.optimizerswitches) and (taicpu(p).oper[0]^.typ=top_reg) and + assigned(FindRegAllocBackward(taicpu(p).oper[0]^.reg,tai(p.Previous))) and (GetNextInstruction(p,hp1)) and MatchInstruction(hp1,A_LDS) and (taicpu(hp1).oper[0]^.typ=top_reg) and + assigned(FindRegAllocBackward(taicpu(hp1).oper[0]^.reg,tai(hp1.Previous))) and (GetNextInstruction(hp1, hp2)) and MatchInstruction(hp2,A_MOV) and (taicpu(hp2).oper[1]^.reg=taicpu(p).oper[0]^.reg) and + assigned(FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(hp2.Next))) and (GetNextInstruction(hp2, hp3)) and MatchInstruction(hp3,A_MOV) and - (taicpu(hp3).oper[1]^.reg=taicpu(hp1).oper[0]^.reg) then + (taicpu(hp3).oper[1]^.reg=taicpu(hp1).oper[0]^.reg) and + assigned(FindRegDeAlloc(taicpu(hp1).oper[0]^.reg,tai(hp3.Next))) then begin DebugMsg('Peephole LdsLdsMovMov2LdsLds performed', p); @@ -498,21 +502,19 @@ Implementation (not RegModifiedBetween(taicpu(p).oper[0]^.reg, p, hp1)) and (not RegUsedBetween(taicpu(hp1).oper[0]^.reg, p, hp1)) then begin - DebugMsg('Peephole LdsMov2Lds performed', p); - alloc:=FindRegAllocBackward(taicpu(p).oper[0]^.reg,tai(p.Previous)); dealloc:=FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(hp1.Next)); if assigned(alloc) and assigned(dealloc) then begin + DebugMsg('Peephole LdsMov2Lds performed', p); asml.Remove(alloc); alloc.Free; asml.Remove(dealloc); dealloc.Free; + taicpu(p).oper[0]^.reg:=taicpu(hp1).oper[0]^.reg; + RemoveInstruction(hp1); + result:=true; end; - - taicpu(p).oper[0]^.reg:=taicpu(hp1).oper[0]^.reg; - RemoveInstruction(hp1); - result:=true; end; end;