What is Constant folding?

An optimization that evaluates expressions whose values are known at compile time and replaces them with the resulting constant, such as turning 3 * 4 into 12. It removes run-time computation.

Field: Compilers

Constant folding in the explanations

Questions that mention Constant folding (5)

  1. Which is an example of constant folding by a compiler?
  2. After repeatedly applying constant propagation and constant folding to the code above, what does it finally become?
  3. After thoroughly applying constant propagation, constant folding and dead-code elimination to the function above, what does it return and what code remains?
  4. Which pair gives the advantage and drawback of function inlining?
  5. In the code above, which optimization applies after inlining sq, and with what result?

Related terms

Loop unrolling Function inlining Abstract syntax tree Basic block Common subexpression elimination Control-flow graph Instruction scheduling Intermediate representation JIT compilation Lexical analysis

Back to the glossary