mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2026-01-04 15:00:53 +01:00
* factored out TX86AsmOptimizer.OptPass2Imul
git-svn-id: trunk@35252 -
This commit is contained in:
parent
ebb2b81f79
commit
f68558b88c
@ -1853,29 +1853,8 @@ begin
|
||||
if DoFpuLoadStoreOpt(p) then
|
||||
continue;
|
||||
A_IMUL:
|
||||
begin
|
||||
if (taicpu(p).ops >= 2) and
|
||||
((taicpu(p).oper[0]^.typ = top_const) or
|
||||
((taicpu(p).oper[0]^.typ = top_ref) and (taicpu(p).oper[0]^.ref^.refaddr=addr_full))) and
|
||||
(taicpu(p).oper[1]^.typ = top_reg) and
|
||||
((taicpu(p).ops = 2) or
|
||||
((taicpu(p).oper[2]^.typ = top_reg) and
|
||||
(taicpu(p).oper[2]^.reg = taicpu(p).oper[1]^.reg))) and
|
||||
getLastInstruction(p,hp1) and
|
||||
(hp1.typ = ait_instruction) and
|
||||
(taicpu(hp1).opcode = A_MOV) and
|
||||
(taicpu(hp1).oper[0]^.typ = top_reg) and
|
||||
(taicpu(hp1).oper[1]^.typ = top_reg) and
|
||||
(taicpu(hp1).oper[1]^.reg = taicpu(p).oper[1]^.reg) then
|
||||
{ change "mov reg1,reg2; imul y,reg2" to "imul y,reg1,reg2" }
|
||||
begin
|
||||
taicpu(p).ops := 3;
|
||||
taicpu(p).loadreg(1,taicpu(hp1).oper[0]^.reg);
|
||||
taicpu(p).loadreg(2,taicpu(hp1).oper[1]^.reg);
|
||||
asml.remove(hp1);
|
||||
hp1.free;
|
||||
end;
|
||||
end;
|
||||
if OptPass2Imul(p) then
|
||||
continue;
|
||||
A_JMP:
|
||||
{
|
||||
change
|
||||
|
||||
@ -46,6 +46,7 @@ unit aoptx86;
|
||||
function OptPass1MOV(var p : tai) : boolean;
|
||||
|
||||
function OptPass2MOV(var p : tai) : boolean;
|
||||
function OptPass2Imul(var p : tai) : boolean;
|
||||
|
||||
procedure DebugMsg(const s : string; p : tai);inline;
|
||||
|
||||
@ -366,7 +367,11 @@ unit aoptx86;
|
||||
((p.oper[0]^.typ = top_ref) and
|
||||
not RegInRef(reg,p.oper[0]^.ref^)))) or
|
||||
((p.opcode = A_POP) and
|
||||
(SuperRegistersEqual(p.oper[0]^.reg,reg)));
|
||||
(SuperRegistersEqual(p.oper[0]^.reg,reg))) or
|
||||
((p.opcode = A_IMUL) and
|
||||
(p.ops=3) and
|
||||
(SuperRegistersEqual(p.oper[2]^.reg,reg)) and
|
||||
not((SuperRegistersEqual(p.oper[1]^.reg,reg))));
|
||||
end;
|
||||
|
||||
|
||||
@ -1173,6 +1178,45 @@ unit aoptx86;
|
||||
end;
|
||||
|
||||
|
||||
function TX86AsmOptimizer.OptPass2Imul(var p : tai) : boolean;
|
||||
var
|
||||
TmpUsedRegs : TAllUsedRegs;
|
||||
hp1 : tai;
|
||||
i : longint;
|
||||
begin
|
||||
Result:=false;
|
||||
if (taicpu(p).ops >= 2) and
|
||||
((taicpu(p).oper[0]^.typ = top_const) or
|
||||
((taicpu(p).oper[0]^.typ = top_ref) and (taicpu(p).oper[0]^.ref^.refaddr=addr_full))) and
|
||||
(taicpu(p).oper[1]^.typ = top_reg) and
|
||||
((taicpu(p).ops = 2) or
|
||||
((taicpu(p).oper[2]^.typ = top_reg) and
|
||||
(taicpu(p).oper[2]^.reg = taicpu(p).oper[1]^.reg))) and
|
||||
GetLastInstruction(p,hp1) and
|
||||
MatchInstruction(hp1,A_MOV,[]) and
|
||||
MatchOpType(hp1,top_reg,top_reg) and
|
||||
((taicpu(hp1).oper[1]^.reg = taicpu(p).oper[1]^.reg) or
|
||||
((taicpu(hp1).opsize=S_L) and (taicpu(p).opsize=S_Q) and SuperRegistersEqual(taicpu(hp1).oper[1]^.reg,taicpu(p).oper[1]^.reg))) then
|
||||
begin
|
||||
CopyUsedRegs(TmpUsedRegs);
|
||||
if not(RegUsedAfterInstruction(taicpu(p).oper[1]^.reg,p,TmpUsedRegs)) then
|
||||
{ change
|
||||
mov reg1,reg2
|
||||
imul y,reg2 to imul y,reg1,reg2 }
|
||||
begin
|
||||
taicpu(p).ops := 3;
|
||||
taicpu(p).loadreg(1,taicpu(hp1).oper[0]^.reg);
|
||||
taicpu(p).loadreg(2,taicpu(hp1).oper[1]^.reg);
|
||||
DebugMsg('Peephole MovImul2Imul done',p);
|
||||
asml.remove(hp1);
|
||||
hp1.free;
|
||||
result:=true;
|
||||
end;
|
||||
ReleaseUsedRegs(TmpUsedRegs);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TX86AsmOptimizer.OptPass1AND(var p : tai) : boolean;
|
||||
var
|
||||
hp1 : tai;
|
||||
|
||||
@ -355,6 +355,8 @@ end;
|
||||
case taicpu(p).opcode of
|
||||
A_MOV:
|
||||
Result:=OptPass2MOV(p);
|
||||
A_IMUL:
|
||||
Result:=OptPass2Imul(p);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user