fipa-pure-const
The fipa-pure-const option allows the compiler to "Discover which functions are pure or constant. Enabled by default at -O and higher."To understand pure functions there are two requirements:
Pure functions examples are:
- The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information or state that may change while program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices.
- Evaluation of the result does not cause any semantically observable side effect or output, such as mutation of mutable objects or output to I/O devices.
sin(x)
, returning the sine of a number xlength(s)
, returning the size of a string s
Implication
for
(
int
i = 0; i < fibonacci(100); ++i)
with the fipa-pure-const the loop becomes
for
(
int
i = 0,end = fibonacci(100); i < end; ++i)
as the fibonacci() doesn't require to be calculated more than once.
fdse
The fdse option allows the compiler to "Perform dead store elimination (DSE) on RTL. Enabled by default at -O and higher."Dead store is a variable that is assigned a value but is not read by any subsequent instruction. Dead store values waste processor time and memory.
Implication
function func(a, b) { var x; var i = 300; while (i--) { x = a + b; // dead store } }
Removing dead store values can have the unintended consequence of not allowing
overwrites to happen.
No comments:
Post a Comment