From 895d0585a89d3c17e269536322d62222f8c5730a Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 11 Feb 2021 15:52:44 -0600 Subject: [PATCH] Small new optimization: "anything % 1" equals 0. --- DAG.pas | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/DAG.pas b/DAG.pas index 51f8a88..784057b 100644 --- a/DAG.pas +++ b/DAG.pas @@ -1638,7 +1638,13 @@ case op^.opcode of {check for optimizations of this node} pc_mdl: begin {pc_mdl} if op^.right^.opcode = pc_ldc then - if op^.left^.opcode = pc_ldc then + if op^.right^.lval = 1 then begin + if not SideEffects(op^.left) then begin + op^.right^.lval := 0; + opv := op^.right; + end; {if} + end {if} + else if op^.left^.opcode = pc_ldc then if (op^.left^.lval >= 0) and (op^.right^.lval > 0) then begin op^.left^.lval := op^.left^.lval mod op^.right^.lval; opv := op^.left; @@ -1647,7 +1653,13 @@ case op^.opcode of {check for optimizations of this node} pc_mod: begin {pc_mod} if op^.right^.opcode = pc_ldc then - if op^.left^.opcode = pc_ldc then + if op^.right^.q = 1 then begin + if not SideEffects(op^.left) then begin + op^.right^.q := 0; + opv := op^.right; + end; {if} + end {if} + else if op^.left^.opcode = pc_ldc then if (op^.left^.q >= 0) and (op^.right^.q > 0) then begin op^.left^.q := op^.left^.q mod op^.right^.q; opv := op^.left; @@ -2145,7 +2157,13 @@ case op^.opcode of {check for optimizations of this node} pc_uim: begin {pc_uim} if op^.right^.opcode = pc_ldc then - if op^.left^.opcode = pc_ldc then + if op^.right^.q = 1 then begin + if not SideEffects(op^.left) then begin + op^.right^.q := 0; + opv := op^.right; + end; {if} + end {if} + else if op^.left^.opcode = pc_ldc then if op^.right^.q <> 0 then begin op^.left^.q := ord(umod(op^.left^.q & $0000FFFF, op^.right^.q & $0000FFFF)); @@ -2170,7 +2188,13 @@ case op^.opcode of {check for optimizations of this node} pc_ulm: begin {pc_ulm} if op^.right^.opcode = pc_ldc then - if op^.left^.opcode = pc_ldc then + if op^.right^.lval = 1 then begin + if not SideEffects(op^.left) then begin + op^.right^.lval := 0; + opv := op^.right; + end; {if} + end {if} + else if op^.left^.opcode = pc_ldc then if op^.right^.lval <> 0 then begin op^.left^.lval := umod(op^.left^.lval, op^.right^.lval); opv := op^.left;