From acddd93ffbf32b96dbb0b3be6bb673e2960f8238 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 6 Mar 2021 23:14:29 -0600 Subject: [PATCH] Avoid a precision reduction in some cases where it is not needed. --- DAG.pas | 21 ++++++++++++++++++--- Gen.pas | 9 +++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/DAG.pas b/DAG.pas index 9a8444b..6a5eba8 100644 --- a/DAG.pas +++ b/DAG.pas @@ -586,7 +586,12 @@ var end; begin {RealStoreOptimizations} - if opl^.opcode = pc_ngr then begin + if opl^.opcode = pc_cnv then + if baseTypeEnum(opl^.q & $000F) = op^.optype then + opl^.q := (opl^.q & $FFF0) | ord(cgExtended); + if (op^.optype = cgComp) or not (op^.opcode in [pc_sro,pc_str,pc_sto]) then + {skip below optimizations} + else if opl^.opcode = pc_ngr then begin same := false; with opl^.left^ do if op^.opcode = pc_sro then begin @@ -1452,6 +1457,16 @@ case op^.opcode of {check for optimizations of this node} end; {else if} end; {case pc_cnv} + pc_cop,pc_cpo: begin {pc_cop,pc_cpo} + if op^.optype in [cgReal,cgDouble,cgExtended,cgComp] then + RealStoreOptimizations(op, op^.left); + end; {case pc_cop,pc_cpo} + + pc_cpi: begin {pc_cpi} + if op^.optype in [cgReal,cgDouble,cgExtended,cgComp] then + RealStoreOptimizations(op, op^.right); + end; {case pc_cpi} + pc_dec: begin {pc_dec} if op^.q = 0 then opv := op^.left @@ -2427,12 +2442,12 @@ case op^.opcode of {check for optimizations of this node} end; {case pc_slq} pc_sro, pc_str: begin {pc_sro, pc_str} - if op^.optype in [cgReal,cgDouble,cgExtended] then + if op^.optype in [cgReal,cgDouble,cgExtended,cgComp] then RealStoreOptimizations(op, op^.left); end; {case pc_sro, pc_str} pc_sto: begin {pc_sto} - if op^.optype in [cgReal,cgDouble,cgExtended] then + if op^.optype in [cgReal,cgDouble,cgExtended,cgComp] then RealStoreOptimizations(op, op^.right); if op^.left^.opcode = pc_lao then begin op^.q := op^.left^.q; diff --git a/Gen.pas b/Gen.pas index f8583d8..1819491 100644 --- a/Gen.pas +++ b/Gen.pas @@ -1731,11 +1731,14 @@ else if op^.q in [wordToByte,uwordToByte] then begin GenNative(m_ora_imm, immediate, $FF00, nil, 0); GenLab(lab1); end {else if} -else if op^.q in [byteToReal,uByteToReal,wordToReal] then - GenCall(11) +else if op^.q in [byteToReal,uByteToReal,wordToReal] then begin + GenCall(11); + toRealType := cgExtended; + end {else if} else if op^.q = uwordToReal then begin GenNative(m_ldx_imm, immediate, 0, nil, 0); GenCall(12); + toRealType := cgExtended; end {else if} else if op^.q in [longToUbyte,ulongToUbyte] then begin if gLong.where = A_X then @@ -1786,6 +1789,8 @@ else if op^.q in [longToReal,uLongToReal] then begin GenCall(12) else GenCall(13); + if toRealType <> cgReal then + toRealType := cgExtended; end {else if} else if op^.q = realToWord then GenCall(14)