Constant folding

Still, some environments that favor performance such as GLSL shaders allow this for constants, which can occasionally cause bugs).

This is of particular importance in the case of floating point operations, whose precise implementation may vary widely.

Constant propagation is implemented in compilers using reaching definition analysis results.

Constant folding and propagation are typically used together to achieve many simplifications and reductions, and their interleaved, iterative application continues until those effects cease.

Consider this unoptimized pseudocode returning a number unknown pending analysis: Applying constant propagation once, followed by constant folding, yields: Repeating both steps twice produces: Having replaced all uses of variables a and b with constants, the compiler's dead-code elimination applies to those variables, leaving: (Boolean constructs vary among languages and compilers, but their details—such as the status, origin, and representation of true—do not affect these optimization principles.)