From 77681333f520d55157353f13183ef0dce9dd0e4e Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 19 Apr 2021 19:54:39 +0000 Subject: [PATCH] * patch by J. Gareth Moreton: AArch64 OptPass1Shift register tracking fault fix, resolves #38691 git-svn-id: trunk@49235 - --- compiler/aarch64/aoptcpu.pas | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/aarch64/aoptcpu.pas b/compiler/aarch64/aoptcpu.pas index 4ef898284e..dc5e327cf2 100644 --- a/compiler/aarch64/aoptcpu.pas +++ b/compiler/aarch64/aoptcpu.pas @@ -379,15 +379,23 @@ Implementation taicpu(hp1).oper[0]^.reg, taicpu(p).oper[1]^.reg, shifterop); + { Make sure the register used in the shifting is tracked all + the way through, otherwise it may become deallocated while + it's still live and cause incorrect optimisations later } + if (taicpu(hp1).oper[0]^.reg <> taicpu(p).oper[1]^.reg) then + begin + TransferUsedRegs(TmpUsedRegs); + UpdateUsedRegs(TmpUsedRegs, tai(p.Next)); + ALlocRegBetween(taicpu(p).oper[1]^.reg, p, hp1, TmpUsedRegs); + end; + taicpu(hp2).fileinfo:=taicpu(hp1).fileinfo; asml.insertbefore(hp2, hp1); - GetNextInstruction(p, hp2); - asml.remove(p); - asml.remove(hp1); - p.free; - hp1.free; - p:=hp2; - DebugMsg('Peephole FoldShiftProcess done', p); + + RemoveInstruction(hp1); + RemoveCurrentp(p); + + DebugMsg('Peephole FoldShiftProcess done', hp2); Result:=true; break; end;