Constant folding
Constant folding and constant propagation are related compiler optimizations used by many modern compilers. An advanced form of constant propagation known as sparse conditional constant propagation can more accurately propagate constants and simultaneously remove dead code.
Constant propagation은 컴파일러 최적화 기법의 하나로, 컴파일 시점에 어떤 변수의 값이 상수임을 알 수 있다면 해당 변수 대신 상수를 직접 사용하도록 하는 것이다. 이로 인해 expression 전체가 상수가 된다면 이를 컴파일 시에 계산한 후 그 결과를 직접 이용할 수 있게 된다. (constant folding)
Example
Constant Propagation is a very simple (in the principle) optimization left to compilers.
The program is thus equivalent to: