diff --git a/DAG.pas b/DAG.pas index a6a3be5..51f8a88 100644 --- a/DAG.pas +++ b/DAG.pas @@ -896,8 +896,10 @@ case op^.opcode of {check for optimizations of this node} opv := op^.left; end {if} else if op^.right^.opcode = pc_ldc then begin - if op^.right^.lval = 0 then - opv := op^.right + if op^.right^.lval = 0 then begin + if not SideEffects(op^.left) then + opv := op^.right; + end {if} else if op^.right^.lval = -1 then opv := op^.left; end; {else if} @@ -911,8 +913,10 @@ case op^.opcode of {check for optimizations of this node} opv := op^.left; end {if} else if op^.right^.opcode = pc_ldc then begin - if op^.right^.lval = -1 then - opv := op^.right + if op^.right^.lval = -1 then begin + if not SideEffects(op^.left) then + opv := op^.right; + end {if} else if op^.right^.lval = 0 then opv := op^.left; end; {else if} @@ -943,8 +947,10 @@ case op^.opcode of {check for optimizations of this node} opv := op^.left; end {if} else if op^.right^.opcode = pc_ldc then begin - if op^.right^.q = 0 then - opv := op^.right + if op^.right^.q = 0 then begin + if not SideEffects(op^.left) then + opv := op^.right; + end {if} else if op^.right^.q = -1 then opv := op^.left; end; {else if} @@ -981,8 +987,10 @@ case op^.opcode of {check for optimizations of this node} opv := op^.left; end {if} else if op^.right^.opcode = pc_ldc then begin - if op^.right^.q = -1 then - opv := op^.right + if op^.right^.q = -1 then begin + if not SideEffects(op^.left) then + opv := op^.right; + end {if} else if op^.right^.q = 0 then opv := op^.left; end; {else if}