mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-26 14:50:32 +02:00
AVR optimization LdsMov2Lds
This commit is contained in:
parent
c49123086d
commit
248082347f
@ -401,6 +401,8 @@ Implementation
|
|||||||
|
|
||||||
|
|
||||||
function TCpuAsmOptimizer.OptPass1LDS(var p : tai) : boolean;
|
function TCpuAsmOptimizer.OptPass1LDS(var p : tai) : boolean;
|
||||||
|
var
|
||||||
|
hp1, hp2, hp3, alloc, dealloc: tai;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (taicpu(p).oper[1]^.ref^.symbol=nil) and
|
if (taicpu(p).oper[1]^.ref^.symbol=nil) and
|
||||||
@ -424,6 +426,93 @@ Implementation
|
|||||||
taicpu(p).loadconst(1,taicpu(p).oper[1]^.ref^.offset-32);
|
taicpu(p).loadconst(1,taicpu(p).oper[1]^.ref^.offset-32);
|
||||||
|
|
||||||
result:=true;
|
result:=true;
|
||||||
|
end
|
||||||
|
|
||||||
|
{ turn
|
||||||
|
alloc reg0
|
||||||
|
alloc reg1
|
||||||
|
lds reg0, label
|
||||||
|
lds reg1, label
|
||||||
|
mov reg2, reg0
|
||||||
|
mov reg3, reg1
|
||||||
|
dealloc reg0
|
||||||
|
dealloc reg1
|
||||||
|
|
||||||
|
into
|
||||||
|
lds reg2, label
|
||||||
|
lds reg3, label
|
||||||
|
}
|
||||||
|
else if not(cs_opt_level3 in current_settings.optimizerswitches) and
|
||||||
|
(taicpu(p).oper[0]^.typ=top_reg) and
|
||||||
|
(GetNextInstruction(p,hp1)) and MatchInstruction(hp1,A_LDS) and
|
||||||
|
(taicpu(hp1).oper[0]^.typ=top_reg) and
|
||||||
|
(GetNextInstruction(hp1, hp2)) and MatchInstruction(hp2,A_MOV) and
|
||||||
|
(taicpu(hp2).oper[1]^.reg=taicpu(p).oper[0]^.reg) and
|
||||||
|
(GetNextInstruction(hp2, hp3)) and MatchInstruction(hp3,A_MOV) and
|
||||||
|
(taicpu(hp3).oper[1]^.reg=taicpu(hp1).oper[0]^.reg) then
|
||||||
|
begin
|
||||||
|
DebugMsg('Peephole LdsLdsMovMov2LdsLds performed', p);
|
||||||
|
|
||||||
|
alloc:=FindRegAllocBackward(taicpu(p).oper[0]^.reg,tai(p.Previous));
|
||||||
|
dealloc:=FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(hp2.Next));
|
||||||
|
if assigned(alloc) and assigned(dealloc) then
|
||||||
|
begin
|
||||||
|
asml.Remove(alloc);
|
||||||
|
alloc.Free;
|
||||||
|
asml.Remove(dealloc);
|
||||||
|
dealloc.Free;
|
||||||
|
end;
|
||||||
|
taicpu(p).oper[0]^.reg:=taicpu(hp2).oper[0]^.reg;
|
||||||
|
RemoveInstruction(hp2);
|
||||||
|
|
||||||
|
alloc:=FindRegAllocBackward(taicpu(hp1).oper[0]^.reg,tai(hp1.Previous));
|
||||||
|
dealloc:=FindRegDeAlloc(taicpu(hp1).oper[0]^.reg,tai(hp3.Next));
|
||||||
|
if assigned(alloc) and assigned(dealloc) then
|
||||||
|
begin
|
||||||
|
asml.Remove(alloc);
|
||||||
|
alloc.Free;
|
||||||
|
asml.Remove(dealloc);
|
||||||
|
dealloc.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
taicpu(hp1).oper[0]^.reg:=taicpu(hp3).oper[0]^.reg;
|
||||||
|
RemoveInstruction(hp3);
|
||||||
|
Result:=true;
|
||||||
|
end
|
||||||
|
|
||||||
|
{ turn
|
||||||
|
alloc reg0
|
||||||
|
lds reg0, label
|
||||||
|
...
|
||||||
|
mov reg1, reg0
|
||||||
|
dealloc reg0
|
||||||
|
|
||||||
|
into
|
||||||
|
lds reg1, label
|
||||||
|
}
|
||||||
|
else if (cs_opt_level3 in current_settings.optimizerswitches) and
|
||||||
|
(taicpu(p).oper[0]^.typ=top_reg) and
|
||||||
|
(GetNextInstructionUsingReg(p,hp1,taicpu(p).oper[0]^.reg)) and
|
||||||
|
MatchInstruction(hp1,A_MOV) and
|
||||||
|
(taicpu(hp1).oper[1]^.reg=taicpu(p).oper[0]^.reg) and
|
||||||
|
(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
|
||||||
|
asml.Remove(alloc);
|
||||||
|
alloc.Free;
|
||||||
|
asml.Remove(dealloc);
|
||||||
|
dealloc.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
taicpu(p).oper[0]^.reg:=taicpu(hp1).oper[0]^.reg;
|
||||||
|
RemoveInstruction(hp1);
|
||||||
|
result:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user