Incomputer science,sparse conditional constant propagation (SCCP) is an optimization frequently applied incompilers after conversion tostatic single assignment form (SSA). Itpropagates constants, which is the calculation of static values which can be calculated at compile time. Moreover, it can find more constant values, and thus more opportunities for improvement, than separately applyingdead code elimination andconstant propagation in any order or any number of repetitions.[1][2]
Thealgorithm operates by performingabstract interpretation of the code in SSA form. During abstract interpretation, it typically uses a flatlattice of constants for values and a global environment mapping SSA variables to values in this lattice. The crux of the algorithm comes in how it handles the interpretation ofbranch instructions. When encountered, the condition for a branch is evaluatedas best possible given the precision of the abstract values bound to variables in the condition. It may be the case that the values are perfectly precise (neither top nor bottom) and hence, abstract execution can decide in which direction to branch. If the values are not constant, or a variable in the condition is undefined, then both branch directions must be taken to remain conservative.
Upon completion of the abstract interpretation, instructions which were never reached are marked as dead code. SSA variables found to have constant values may then be inlined at (propagated to) their point of use.[example needed]