Skip to content

[Cross-platform / Bug Fix] Inc/Dec -> Add/Sub now removes the "nf_modify" flag on the destination

Summary

This merge request fixes an inefficiency in tinlinenode.getaddsub_for_incdec where the destination retained the nf_modify flag (since the parameter of Inc/Dec is read-write). This caused constant propagation and data-flow analysis to not optimise out previous writes. For example, x := 1; Inc(x); would result in the equivalent of x := 1; x := 2;, with the compiler unable to remove x := 1; because the x in x := 2; has the nf_modify flag, thus implying the expression depends on the previous value of x.

System

  • Processor architecture: Cross-platform

What is the current bug behavior?

Constant propagation and data flow analysis doesn't efficiently handle Inc and Dec intrinsics.

What is the behavior after applying this patch?

Inc and Dec are now more efficiently optimised.

Additional notes

No cases of more efficient code have appeared in the compiler, RTL or packages, but as is becoming common in these small merge requests, the inefficiency causes pure function analysis (!645) to fail if the function uses Inc and Dec because it can't fully collapse the node tree into a single assignment.

Merge request reports