mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 20:09:23 +02:00
* x86: Fixed "Cmp1Jl2Cmp0Jle" and "CmpJe2NegJo" optimisations
being applied incorrectly if another jump follows
This commit is contained in:
parent
e406cbd9c8
commit
ae927b0689
@ -7873,7 +7873,7 @@ unit aoptx86;
|
||||
function TX86AsmOptimizer.OptPass1Cmp(var p: tai): boolean;
|
||||
var
|
||||
v: TCGInt;
|
||||
hp1, hp2, p_dist, p_jump, hp1_dist, p_label, hp1_label: tai;
|
||||
true_hp1, hp1, hp2, p_dist, p_jump, hp1_dist, p_label, hp1_label: tai;
|
||||
FirstMatch, TempBool: Boolean;
|
||||
NewReg: TRegister;
|
||||
JumpLabel, JumpLabel_dist, JumpLabel_far: TAsmLabel;
|
||||
@ -7884,6 +7884,8 @@ unit aoptx86;
|
||||
if not GetNextInstruction(p, hp1) then
|
||||
Exit;
|
||||
|
||||
true_hp1 := hp1;
|
||||
|
||||
{ Search for:
|
||||
cmp ###,###
|
||||
j(c1) @lbl1
|
||||
@ -8058,6 +8060,8 @@ unit aoptx86;
|
||||
) then
|
||||
begin
|
||||
DebugMsg(SPeepholeOptimization + 'CMP/Jcc/CMP; removed superfluous CMP', hp2);
|
||||
TransferUsedRegs(TmpUsedRegs);
|
||||
AllocRegBetween(NR_DEFAULTFLAGS, p, hp2, TmpUsedRegs);
|
||||
RemoveInstruction(hp2);
|
||||
Result := True;
|
||||
{ Continue the while loop in case "Jcc/CMP" follows the second CMP that was just removed }
|
||||
@ -8075,7 +8079,7 @@ unit aoptx86;
|
||||
|
||||
if (
|
||||
{ Don't call GetNextInstruction again if we already have it }
|
||||
(hp1 = p_jump) or
|
||||
(true_hp1 = p_jump) or
|
||||
GetNextInstruction(p, hp1)
|
||||
) and
|
||||
MatchInstruction(hp1, A_Jcc, []) and
|
||||
@ -8210,12 +8214,12 @@ unit aoptx86;
|
||||
end;
|
||||
end;
|
||||
|
||||
if taicpu(p).oper[0]^.typ = top_const then
|
||||
if (taicpu(p).oper[0]^.typ = top_const) and
|
||||
MatchInstruction(hp1,A_Jcc,A_SETcc,[]) then
|
||||
begin
|
||||
|
||||
if (taicpu(p).oper[0]^.val = 0) and
|
||||
(taicpu(p).oper[1]^.typ = top_reg) and
|
||||
MatchInstruction(hp1,A_Jcc,A_SETcc,[]) then
|
||||
(taicpu(p).oper[1]^.typ = top_reg) then
|
||||
begin
|
||||
hp2 := p;
|
||||
FirstMatch := True;
|
||||
@ -8232,6 +8236,7 @@ unit aoptx86;
|
||||
MatchInstruction(hp1,A_Jcc,A_SETcc,[])
|
||||
) do
|
||||
begin
|
||||
Prefetch(hp1.Next);
|
||||
FirstMatch := False;
|
||||
case taicpu(hp1).condition of
|
||||
C_B, C_C, C_NAE, C_O:
|
||||
@ -8316,8 +8321,14 @@ unit aoptx86;
|
||||
Result := True;
|
||||
Exit;
|
||||
end
|
||||
else if (taicpu(p).oper[0]^.val = 1) and
|
||||
MatchInstruction(hp1,A_Jcc,A_SETcc,[]) and
|
||||
else
|
||||
begin
|
||||
TransferUsedRegs(TmpUsedRegs);
|
||||
UpdateUsedRegs(TmpUsedRegs, tai(p.Next));
|
||||
|
||||
if not RegUsedAfterInstruction(NR_DEFAULTFLAGS, hp1, TmpUsedRegs) then
|
||||
begin
|
||||
if (taicpu(p).oper[0]^.val = 1) and
|
||||
(taicpu(hp1).condition in [C_L, C_NL, C_NGE, C_GE]) then
|
||||
begin
|
||||
{ Convert; To:
|
||||
@ -8364,7 +8375,6 @@ unit aoptx86;
|
||||
end;
|
||||
|
||||
if (taicpu(p).oper[0]^.val=v) and
|
||||
MatchInstruction(hp1,A_Jcc,A_SETcc,[]) and
|
||||
(Taicpu(hp1).condition in [C_E,C_NE]) then
|
||||
begin
|
||||
TransferUsedRegs(TmpUsedRegs);
|
||||
@ -8386,6 +8396,8 @@ unit aoptx86;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
if TrySwapMovCmp(p, hp1) then
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user