From 7c5847bc70613f8a06bb4249e020bd259fef8c13 Mon Sep 17 00:00:00 2001 From: "J. Gareth \"Curious Kit\" Moreton" Date: Fri, 23 Feb 2024 18:06:14 +0000 Subject: [PATCH] * x86: "StcClcSet(c)2Mov" optimisation now checks to see if the destination register is in use --- compiler/x86/aoptx86.pas | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas index 44f9cfddae..7ed7ecc7dd 100644 --- a/compiler/x86/aoptx86.pas +++ b/compiler/x86/aoptx86.pas @@ -9578,7 +9578,13 @@ unit aoptx86; IsJumpToLabel(taicpu(hp1_dist)) and not (taicpu(hp1_dist).condition in [C_AE, C_NB, C_NC, C_B, C_C, C_NAE, C_BE, C_NA]) and { This works if hp1_dist or both are regular JMP instructions } - condition_in(taicpu(hp1).condition, taicpu(hp1_dist).condition) then + condition_in(taicpu(hp1).condition, taicpu(hp1_dist).condition) and + ( + (taicpu(p_dist).oper[0]^.typ <> top_reg) or + { Make sure the register isn't still in use, otherwise it + may get corrupted (fixes #40659) } + not RegUsedBetween(taicpu(p_dist).oper[0]^.reg, p, p_dist) + ) then begin taicpu(p).allocate_oper(2); taicpu(p).ops := 2;