From f24f37aa9f195c3b702c12c4e74722c45e99a9ae Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 12 Jan 2018 22:32:12 -0600 Subject: [PATCH] Generate more efficient stack repair code (2). Previously, the stack repair code always generated code to save and restore a register, but this can be omitted except in cases where a 32-bit value or pointer is returned. --- Gen.pas | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Gen.pas b/Gen.pas index 408e8be..0068af3 100644 --- a/Gen.pas +++ b/Gen.pas @@ -4081,10 +4081,12 @@ procedure GenTree {op: icptr}; end {if} else if saveStack or (op^.q <> 0) then begin stackSaveDepth := stackSaveDepth - 1; - GenImplied(m_txy); + if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then + GenImplied(m_txy); GenNative(m_ldx_dir, direct, stackLoc, nil, 0); GenImplied(m_txs); - GenImplied(m_tyx); + if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then + GenImplied(m_tyx); if stackSaveDepth <> 0 then begin GenImplied(m_ply); GenNative(m_sty_dir, direct, stackLoc, nil, 0); @@ -4137,14 +4139,16 @@ procedure GenTree {op: icptr}; end {if} else if saveStack or (op^.q <> 0) then begin stackSaveDepth := stackSaveDepth - 1; - GenImplied(m_tay); - GenNative(m_lda_dir, direct, stackLoc, nil, 0); - GenImplied(m_tcs); + if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then + GenImplied(m_txy); + GenNative(m_ldx_dir, direct, stackLoc, nil, 0); + GenImplied(m_txs); + if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then + GenImplied(m_tyx); if stackSaveDepth <> 0 then begin - GenImplied(m_pla); - GenNative(m_sta_dir, direct, stackLoc, nil, 0); + GenImplied(m_ply); + GenNative(m_sty_dir, direct, stackLoc, nil, 0); end; {if} - GenImplied(m_tya); end; {else} {save the returned value}