+ optimize nil - val into - val

This commit is contained in:
florian 2026-01-20 23:13:04 +01:00
parent bc2af0d6d6
commit 16a9651046
2 changed files with 5 additions and 1 deletions

View File

@ -1018,6 +1018,10 @@ const
result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef);
end
{ change "nil - val" to "-val" }
else if (left.nodetype=niln) and is_pointer(right.resultdef) then
result := ctypeconvnode.create_internal(cunaryminusnode.create(ctypeconvnode.create_internal(right.getcopy,resultdef)),resultdef)
{ convert n - n mod const into n div const*const }
else if (right.nodetype=modn) and is_constintnode(tmoddivnode(right).right) and
(left.isequal(tmoddivnode(right).left)) and not(might_have_sideeffects(left)) { and

View File

@ -1013,7 +1013,7 @@ implementation
constructor tunaryminusnode.create(expr : tnode);
begin
inherited create(unaryminusn,expr);
inherited create(unaryminusn,expr);
end;