From be448e29f63fd5d5d2b4320f24bde4ec197ca895 Mon Sep 17 00:00:00 2001 From: "J. Gareth \"Curious Kit\" Moreton" Date: Wed, 15 Dec 2021 16:37:31 +0000 Subject: [PATCH] Fixed bug in new TEST optimisation where a FLAGS check always returned "in use" --- compiler/x86/aoptx86.pas | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas index 6d37c1ad04..6be48adddb 100644 --- a/compiler/x86/aoptx86.pas +++ b/compiler/x86/aoptx86.pas @@ -4519,6 +4519,8 @@ unit aoptx86; { Only remove the second test if no jumps or other conditional instructions follow } TransferUsedRegs(TmpUsedRegs); + UpdateUsedRegs(TmpUsedRegs, tai(p.Next)); + UpdateUsedRegs(TmpUsedRegs, tai(hp1.Next)); if not RegUsedAfterInstruction(NR_DEFAULTFLAGS, p_dist, TmpUsedRegs) then RemoveInstruction(p_dist); @@ -4559,12 +4561,15 @@ unit aoptx86; TAsmLabel(taicpu(hp1_dist).oper[0]^.ref^.symbol).DecRefs; DebugMsg(SPeepholeOptimization + 'TEST/JNE/TEST/JNE merged', p); + RemoveInstruction(hp1_dist); + { Only remove the second test if no jumps or other conditional instructions follow } TransferUsedRegs(TmpUsedRegs); + UpdateUsedRegs(TmpUsedRegs, tai(p.Next)); + UpdateUsedRegs(TmpUsedRegs, tai(hp1.Next)); if not RegUsedAfterInstruction(NR_DEFAULTFLAGS, p_dist, TmpUsedRegs) then RemoveInstruction(p_dist); - RemoveInstruction(hp1_dist); Result := True; Exit; end;