From b514e979bdf7fd53556ba1d58dd5915bb1308f53 Mon Sep 17 00:00:00 2001 From: "J. Gareth \"Curious Kit\" Moreton" Date: Thu, 25 Jan 2024 22:39:17 +0000 Subject: [PATCH] * Fixed issue where OptPass2CMP and OptPass2TEST didn't drop out on labels etc. --- compiler/x86/aoptx86.pas | 96 ++++++++++++++++++++----------------- compiler/x86_64/aoptcpu.pas | 2 - 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas index 36cfae3c11..d07f59f2e2 100644 --- a/compiler/x86/aoptx86.pas +++ b/compiler/x86/aoptx86.pas @@ -11838,6 +11838,9 @@ unit aoptx86; hp2 := hp1; while GetNextInstruction(hp2, hp2) and (hp2 <> BlockEnd) do begin + if (hp2.typ <> ait_instruction) then + Exit; + case taicpu(hp2).opcode of A_MOV: begin @@ -11987,29 +11990,32 @@ unit aoptx86; while GetNextInstruction(hp1, hp1) and (hp1 <> BlockEnd) do begin - if (hp1.typ = ait_instruction) then - begin - case taicpu(hp1).opcode of - A_MOV: - { Ignore regular MOVs unless they are obviously not related - to a CMOV block } - if taicpu(hp1).oper[1]^.typ <> top_reg then - Break; - A_CMOVcc: - if TryCmpCMovOpts(pCond, hp1) then - begin - hp1 := hp2; + if (hp1.typ <> ait_instruction) then + { Break out on markers and labels etc. } + Break; - { p itself isn't changed, and we're still inside a - while loop to catch subsequent CMOVs, so just flag - a new iteration } - Include(OptsToCheck, aoc_ForceNewIteration); - Continue; - end; - else - Break; - end; - end; + case taicpu(hp1).opcode of + A_MOV: + { Ignore regular MOVs unless they are obviously not related + to a CMOV block } + if taicpu(hp1).oper[1]^.typ <> top_reg then + Break; + A_CMOVcc: + if TryCmpCMovOpts(pCond, hp1) then + begin + hp1 := hp2; + + { p itself isn't changed, and we're still inside a + while loop to catch subsequent CMOVs, so just flag + a new iteration } + Include(OptsToCheck, aoc_ForceNewIteration); + Continue; + end; + + else + { Drop out if we find anything else } + Break; + end; hp2 := hp1; end; @@ -12039,29 +12045,31 @@ unit aoptx86; while GetNextInstruction(hp1, hp1) and (hp1 <> BlockEnd) do begin - if (hp1.typ = ait_instruction) then - begin - case taicpu(hp1).opcode of - A_MOV: - { Ignore regular MOVs unless they are obviously not related - to a CMOV block } - if taicpu(hp1).oper[1]^.typ <> top_reg then - Break; - A_CMOVcc: - if TryCmpCMovOpts(pCond, hp1) then - begin - hp1 := hp2; + if (hp1.typ <> ait_instruction) then + { Break out on markers and labels etc. } + Break; - { p itself isn't changed, and we're still inside a - while loop to catch subsequent CMOVs, so just flag - a new iteration } - Include(OptsToCheck, aoc_ForceNewIteration); - Continue; - end; - else - Break; - end; - end; + case taicpu(hp1).opcode of + A_MOV: + { Ignore regular MOVs unless they are obviously not related + to a CMOV block } + if taicpu(hp1).oper[1]^.typ <> top_reg then + Break; + A_CMOVcc: + if TryCmpCMovOpts(pCond, hp1) then + begin + hp1 := hp2; + + { p itself isn't changed, and we're still inside a + while loop to catch subsequent CMOVs, so just flag + a new iteration } + Include(OptsToCheck, aoc_ForceNewIteration); + Continue; + end; + else + { Drop out if we find anything else } + Break; + end; hp2 := hp1; end; diff --git a/compiler/x86_64/aoptcpu.pas b/compiler/x86_64/aoptcpu.pas index 7e56e3a255..430f2610e9 100644 --- a/compiler/x86_64/aoptcpu.pas +++ b/compiler/x86_64/aoptcpu.pas @@ -228,12 +228,10 @@ uses Result:=OptPass2ADD(p); A_SETcc: result:=OptPass2SETcc(p); -{ disable for now as the it seems to cause buggy code A_CMP: Result:=OptPass2CMP(p); A_TEST: Result:=OptPass2TEST(p); -} else ; end;