Small new optimization: "anything % 1" equals 0.

This commit is contained in:
Stephen Heumann 2021-02-11 15:52:44 -06:00
parent 8078675aae
commit 895d0585a8

32
DAG.pas
View File

@ -1638,7 +1638,13 @@ case op^.opcode of {check for optimizations of this node}
pc_mdl: begin {pc_mdl} pc_mdl: begin {pc_mdl}
if op^.right^.opcode = pc_ldc then 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 if (op^.left^.lval >= 0) and (op^.right^.lval > 0) then begin
op^.left^.lval := op^.left^.lval mod op^.right^.lval; op^.left^.lval := op^.left^.lval mod op^.right^.lval;
opv := op^.left; opv := op^.left;
@ -1647,7 +1653,13 @@ case op^.opcode of {check for optimizations of this node}
pc_mod: begin {pc_mod} pc_mod: begin {pc_mod}
if op^.right^.opcode = pc_ldc then 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 if (op^.left^.q >= 0) and (op^.right^.q > 0) then begin
op^.left^.q := op^.left^.q mod op^.right^.q; op^.left^.q := op^.left^.q mod op^.right^.q;
opv := op^.left; opv := op^.left;
@ -2145,7 +2157,13 @@ case op^.opcode of {check for optimizations of this node}
pc_uim: begin {pc_uim} pc_uim: begin {pc_uim}
if op^.right^.opcode = pc_ldc then 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 if op^.right^.q <> 0 then begin
op^.left^.q := op^.left^.q :=
ord(umod(op^.left^.q & $0000FFFF, op^.right^.q & $0000FFFF)); 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} pc_ulm: begin {pc_ulm}
if op^.right^.opcode = pc_ldc then 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 if op^.right^.lval <> 0 then begin
op^.left^.lval := umod(op^.left^.lval, op^.right^.lval); op^.left^.lval := umod(op^.left^.lval, op^.right^.lval);
opv := op^.left; opv := op^.left;