mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 02:45:58 +02:00
* remove unneeded zero extensions from 16 to 32 Bit
git-svn-id: trunk@21404 -
This commit is contained in:
parent
28e9d10c1f
commit
9e180fb318
@ -205,7 +205,7 @@ Implementation
|
|||||||
var
|
var
|
||||||
hp1,hp2: tai;
|
hp1,hp2: tai;
|
||||||
i: longint;
|
i: longint;
|
||||||
|
TmpUsedRegs: TAllUsedRegs;
|
||||||
begin
|
begin
|
||||||
result := false;
|
result := false;
|
||||||
case p.typ of
|
case p.typ of
|
||||||
@ -243,9 +243,9 @@ Implementation
|
|||||||
else
|
else
|
||||||
*)
|
*)
|
||||||
case taicpu(p).opcode of
|
case taicpu(p).opcode of
|
||||||
A_STR,
|
A_STR {,
|
||||||
A_STRH,
|
A_STRH,
|
||||||
A_STRB:
|
A_STRB }:
|
||||||
begin
|
begin
|
||||||
{ change
|
{ change
|
||||||
str reg1,ref
|
str reg1,ref
|
||||||
@ -255,6 +255,7 @@ Implementation
|
|||||||
mov reg2,reg1
|
mov reg2,reg1
|
||||||
}
|
}
|
||||||
if (taicpu(p).oper[1]^.ref^.addressmode=AM_OFFSET) and
|
if (taicpu(p).oper[1]^.ref^.addressmode=AM_OFFSET) and
|
||||||
|
(taicpu(p).oppostfix=PF_None) and
|
||||||
GetNextInstruction(p,hp1) and
|
GetNextInstruction(p,hp1) and
|
||||||
(
|
(
|
||||||
( (taicpu(p).opcode = A_STR) and
|
( (taicpu(p).opcode = A_STR) and
|
||||||
@ -354,34 +355,73 @@ Implementation
|
|||||||
MatchOperand(taicpu(hp1).oper[0]^, taicpu(p).oper[0]^.reg) and
|
MatchOperand(taicpu(hp1).oper[0]^, taicpu(p).oper[0]^.reg) and
|
||||||
MatchOperand(taicpu(hp1).oper[1]^, taicpu(p).oper[0]^.reg) and
|
MatchOperand(taicpu(hp1).oper[1]^, taicpu(p).oper[0]^.reg) and
|
||||||
(taicpu(hp1).oper[2]^.typ = top_shifterop) and
|
(taicpu(hp1).oper[2]^.typ = top_shifterop) and
|
||||||
(taicpu(hp1).oper[2]^.shifterop^.rs = NR_NO) and
|
(taicpu(hp1).oper[2]^.shifterop^.rs = NR_NO) then
|
||||||
(taicpu(p).oper[2]^.shifterop^.shiftmode=taicpu(hp1).oper[2]^.shifterop^.shiftmode) then
|
|
||||||
begin
|
begin
|
||||||
inc(taicpu(p).oper[2]^.shifterop^.shiftimm,taicpu(hp1).oper[2]^.shifterop^.shiftimm);
|
{ fold
|
||||||
{ avoid overflows }
|
mov reg1,reg0, lsl 16
|
||||||
if taicpu(p).oper[2]^.shifterop^.shiftimm>31 then
|
mov reg1,reg1, lsr 16
|
||||||
case taicpu(p).oper[2]^.shifterop^.shiftmode of
|
strh reg1, ...
|
||||||
SM_ROR:
|
dealloc reg1
|
||||||
taicpu(p).oper[2]^.shifterop^.shiftimm:=taicpu(p).oper[2]^.shifterop^.shiftimm and 31;
|
to
|
||||||
SM_ASR:
|
strh reg1, ...
|
||||||
taicpu(p).oper[2]^.shifterop^.shiftimm:=31;
|
dealloc reg1
|
||||||
SM_LSR,
|
}
|
||||||
SM_LSL:
|
if (taicpu(p).oper[2]^.shifterop^.shiftmode=SM_LSL) and
|
||||||
|
(taicpu(p).oper[2]^.shifterop^.shiftimm=16) and
|
||||||
|
(taicpu(hp1).oper[2]^.shifterop^.shiftmode=SM_LSR) and
|
||||||
|
(taicpu(hp1).oper[2]^.shifterop^.shiftimm=16) and
|
||||||
|
getnextinstruction(hp1,hp2) and
|
||||||
|
MatchInstruction(hp2, A_STR, [taicpu(p).condition], [PF_H]) and
|
||||||
|
MatchOperand(taicpu(hp2).oper[0]^, taicpu(p).oper[0]^.reg) then
|
||||||
|
begin
|
||||||
|
CopyUsedRegs(TmpUsedRegs);
|
||||||
|
UpdateUsedRegs(TmpUsedRegs, tai(p.next));
|
||||||
|
UpdateUsedRegs(TmpUsedRegs, tai(hp1.next));
|
||||||
|
if not(RegUsedAfterInstruction(taicpu(p).oper[0]^.reg,hp2,TmpUsedRegs)) then
|
||||||
begin
|
begin
|
||||||
hp1:=taicpu.op_reg_const(A_MOV,taicpu(p).oper[0]^.reg,0);
|
asml.insertbefore(tai_comment.Create(strpnew('Peephole optimizer removed superfluous 16 Bit zero extension')), hp1);
|
||||||
InsertLLItem(p.previous, p.next, hp1);
|
taicpu(hp2).loadreg(0,taicpu(p).oper[1]^.reg);
|
||||||
|
asml.remove(p);
|
||||||
|
asml.remove(hp1);
|
||||||
p.free;
|
p.free;
|
||||||
p:=hp1;
|
hp1.free;
|
||||||
|
p:=hp2;
|
||||||
end;
|
end;
|
||||||
else
|
ReleaseUsedRegs(TmpUsedRegs);
|
||||||
internalerror(2008072803);
|
end
|
||||||
|
{ fold
|
||||||
|
mov reg1,reg0, shift imm1
|
||||||
|
mov reg1,reg1, shift imm2
|
||||||
|
to
|
||||||
|
mov reg1,reg0, shift imm1+imm2
|
||||||
|
}
|
||||||
|
else if (taicpu(p).oper[2]^.shifterop^.shiftmode=taicpu(hp1).oper[2]^.shifterop^.shiftmode) then
|
||||||
|
begin
|
||||||
|
inc(taicpu(p).oper[2]^.shifterop^.shiftimm,taicpu(hp1).oper[2]^.shifterop^.shiftimm);
|
||||||
|
{ avoid overflows }
|
||||||
|
if taicpu(p).oper[2]^.shifterop^.shiftimm>31 then
|
||||||
|
case taicpu(p).oper[2]^.shifterop^.shiftmode of
|
||||||
|
SM_ROR:
|
||||||
|
taicpu(p).oper[2]^.shifterop^.shiftimm:=taicpu(p).oper[2]^.shifterop^.shiftimm and 31;
|
||||||
|
SM_ASR:
|
||||||
|
taicpu(p).oper[2]^.shifterop^.shiftimm:=31;
|
||||||
|
SM_LSR,
|
||||||
|
SM_LSL:
|
||||||
|
begin
|
||||||
|
hp1:=taicpu.op_reg_const(A_MOV,taicpu(p).oper[0]^.reg,0);
|
||||||
|
InsertLLItem(p.previous, p.next, hp1);
|
||||||
|
p.free;
|
||||||
|
p:=hp1;
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
internalerror(2008072803);
|
||||||
|
end;
|
||||||
|
asml.insertbefore(tai_comment.Create(strpnew('Peephole ShiftShift2Shift done')), p);
|
||||||
|
asml.remove(hp1);
|
||||||
|
hp1.free;
|
||||||
|
result := true;
|
||||||
end;
|
end;
|
||||||
asml.insertbefore(tai_comment.Create(strpnew('Peephole ShiftShift2Shift done')), p);
|
|
||||||
asml.remove(hp1);
|
|
||||||
hp1.free;
|
|
||||||
result := true;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
{
|
||||||
This changes the very common
|
This changes the very common
|
||||||
mov r0, #0
|
mov r0, #0
|
||||||
|
Loading…
Reference in New Issue
Block a user