mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 22:46:01 +02:00
* x86: Registers are now allocated properly during a FuncMov2Func
optimisation
This commit is contained in:
parent
18eec3055e
commit
3cae3e7e48
@ -2902,7 +2902,7 @@ unit aoptx86;
|
|||||||
|
|
||||||
function TX86AsmOptimizer.FuncMov2Func(var p: tai; const hp1: tai): Boolean;
|
function TX86AsmOptimizer.FuncMov2Func(var p: tai; const hp1: tai): Boolean;
|
||||||
var
|
var
|
||||||
hp2: tai;
|
hp2, hp_regalloc: tai;
|
||||||
p_SourceReg, p_TargetReg: TRegister;
|
p_SourceReg, p_TargetReg: TRegister;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -2962,15 +2962,32 @@ unit aoptx86;
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
DebugMsg(SPeepholeOptimization + 'Removed MOV and changed destination on previous instruction to optimise register usage (FuncMov2Func)', p);
|
DebugMsg(SPeepholeOptimization + 'Removed MOV and changed destination on previous instruction to optimise register usage (FuncMov2Func)', p);
|
||||||
taicpu(hp2).oper[taicpu(hp2).ops-1]^.reg := p_TargetReg;
|
|
||||||
|
{ if %reg2 (p_SourceReg) is allocated before func., remove it completely }
|
||||||
|
hp_regalloc := FindRegAllocBackward(p_SourceReg, hp2);
|
||||||
|
if Assigned(hp_regalloc) then
|
||||||
|
begin
|
||||||
|
Asml.Remove(hp_regalloc);
|
||||||
|
|
||||||
|
if Assigned(FindRegDealloc(p_SourceReg, p)) then
|
||||||
|
begin
|
||||||
|
ExcludeRegFromUsedRegs(p_SourceReg, UsedRegs);
|
||||||
|
hp_regalloc.Free;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{ If the register is not explicitly deallocated, it's
|
||||||
|
being reused, so move the allocation to after func. }
|
||||||
|
AsmL.InsertAfter(hp_regalloc, hp2);
|
||||||
|
end;
|
||||||
|
|
||||||
if not RegInInstruction(p_TargetReg, hp2) then
|
if not RegInInstruction(p_TargetReg, hp2) then
|
||||||
begin
|
begin
|
||||||
{ Since we're allocating from an earlier point, we
|
TransferUsedRegs(TmpUsedRegs);
|
||||||
need to remove the register from the tracking }
|
|
||||||
ExcludeRegFromUsedRegs(p_TargetReg, TmpUsedRegs);
|
|
||||||
AllocRegBetween(p_TargetReg, hp2, p, TmpUsedRegs);
|
AllocRegBetween(p_TargetReg, hp2, p, TmpUsedRegs);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ Actually make the changes }
|
||||||
|
taicpu(hp2).oper[taicpu(hp2).ops-1]^.reg := p_TargetReg;
|
||||||
RemoveCurrentp(p, hp1);
|
RemoveCurrentp(p, hp1);
|
||||||
|
|
||||||
{ If the Func was another MOV instruction, we might get
|
{ If the Func was another MOV instruction, we might get
|
||||||
|
Loading…
Reference in New Issue
Block a user