Compiler Optimization of Deterministic Functions

I read about deterministic execution, which for the same input has the same result. I was wondering if any compiler author was thinking about optimizing deterministic functions at runtime. For example, take a factorial function. If at runtime it is found that it is constantly called with the same input value, the compiler can cache the output value and instead of executing a factorial function, it can directly use this output value. Sounds like a good research topic. Are there any documents or work on this topic?

+3
source share
4 answers

This is usually called memoization and is a fairly common optimization in functional languages.

+4
source

This can be done, but as far as I know, this is not the case for compilers. The trouble is that users can define as many types as they like, and equality in any way they like, but with heap distribution, etc. It is very, very difficult to prove. In principle, this can be done, but only if your function is connected with direct numerical calculation, which is rare, and therefore, it usually does not have high value.

+1
source

http://blogs.msdn.com/b/vcblog/archive/2008/11/12/pogo.aspx talks about optimizing your profile.

doesn't answer your questions as such, but generally talks about using runtime behavior to optimize your build

+1
source

All Articles