> Unfortunately things are much worse for true proc calls. I have never managed > to tell the Nim compiler that it should optimize the second proc call when > arguments are unchanged to the first one. There was a forum thread from me > about that topic some years ago.
You need to tag the proc in C with `__attribute__((const))` (via codegendecl) >From ARM docs (but also GCC and Clang) > The const function attribute specifies that a function examines only its > arguments, and has no effect except for the return value. That is, the > function does not read or modify any global memory. If a function is known to > operate only on its arguments then it can be subject to common sub-expression > elimination and loop optimizations. This attribute is stricter than > __attribute__((pure)) because functions are not permitted to read global > memory. This similar to Nim "no sideeffect" Closely related is `__attribute__((pure))` > Many functions have no effects except to return a value, and their return > value depends only on the parameters and global variables. Functions of this > kind can be subject to data flow analysis and might be eliminated. Note that those don't know about Nim refs, seq, strings and dynamic memory which are considered not considered side-effect in Nim but should be side-effect in C.