Integer folds and identities

The same walk folds an instruction before it looks it up, so what it folds to is what the next ones are numbered with (spirv-opt's constant folding and instruction simplification, for what the translators write). Only 32-bit integers of either sign and booleans, on constants that are no specialization constants:

An instruction becomes one of its operands only when that operand has the instruction's type: a signed sum of an unsigned value and zero stays. A constant result reads the module's constant of that type and value; when there is none, the instruction's own id becomes that constant, declared before the first function in the room the instruction left, so a module never grows. Float arithmetic, divisions and a decorated instruction are not folded.

On the Maxwell translator's modules: x + 0 for a register's offset, masks and shifts of immediates, selects on a constant condition, and bitcasts there and back; an address less its base ((y + 192) - y), whose shifts and sums the known bits then fold; and a predicate made of a masked register, (x & m) != 0 || !(x == 0), which is !(x == 0).


Made from docs/layers/gpu/spirv-opt.md at 69237645142c. GPL-3.0-or-later.