From c21bf747fb3d5750ce62ef49ad5334528e2880ba Mon Sep 17 00:00:00 2001 From: "J. Gareth \"Curious Kit\" Moreton" Date: Wed, 16 Nov 2022 18:25:01 +0000 Subject: [PATCH] * x86: Extension to Cmp1Jl2Cmp0Jle to catch inverted variant --- compiler/x86/aoptx86.pas | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas index fcb0fe9419..0c6bf2e3d7 100644 --- a/compiler/x86/aoptx86.pas +++ b/compiler/x86/aoptx86.pas @@ -7679,31 +7679,31 @@ unit aoptx86; end else if (taicpu(p).oper[0]^.val = 1) and MatchInstruction(hp1,A_Jcc,A_SETcc,[]) and - (taicpu(hp1).condition in [C_L, C_NGE]) then + (taicpu(hp1).condition in [C_L, C_NL, C_NGE, C_GE]) then begin { Convert; To: cmp $1,r/m cmp $0,r/m jl @lbl jle @lbl + (Also do inverted conditions) } DebugMsg(SPeepholeOptimization + 'Cmp1Jl2Cmp0Jle', p); taicpu(p).oper[0]^.val := 0; - taicpu(hp1).condition := C_LE; + if taicpu(hp1).condition in [C_L, C_NGE] then + taicpu(hp1).condition := C_LE + else + taicpu(hp1).condition := C_NLE; { If the instruction is now "cmp $0,%reg", convert it to a TEST (and effectively do the work of the "cmp $0,%reg" in the block above) - - If it's a reference, we can get away with not setting - Result to True because he haven't evaluated the jump - in this pass yet. } if (taicpu(p).oper[1]^.typ = top_reg) then begin taicpu(p).opcode := A_TEST; taicpu(p).loadreg(0,taicpu(p).oper[1]^.reg); - Result := True; end; + Result := True; Exit; end else if (taicpu(p).oper[1]^.typ = top_reg)