Constant folding is a compiler optimization that evaluates expressions whose values are already known at compile time and replaces them with the computed result, so that an expression such as 2 times 3 becomes 6 before the program ever runs. The terms involved are usually literals, but they can also be variables whose values the compiler knows. The technique can use arithmetic identities, though not for IEEE floating point numbers where a value could be infinity or not a number, and it can apply to strings, so that concatenating the literals abc and def yields abcdef. It is often combined with constant propagation, which substitutes variables known to be constant, and an advanced form called sparse conditional constant propagation can propagate constants more precisely while removing dead code. Cross compilers must make sure folded arithmetic behaves as it would on the target machine.
Connections
In Field
Source Constant folding (Wikipedia)
Sources
Constant folding (Wikipedia)
In Group: Compiler and Language Implementation Techniques, Lead section
evaluate expressions whose values are known at compile time and replaces them with the computed result
In Field: Programming Language Theory, Lead section
evaluate expressions whose values are known at compile time and replaces them with the computed result
View the SourceReader Challenges (0)
No disputes yet. Spotted an error or a better source? Open the first one.
Sign in to dispute this or suggest a correction.