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:
OpIMul and the logical instructions; every other integer instruction on constants has all
its bits known (below);x - x, x ^ x, false && x, true || x (x & 0, x * 0 and x | ~0 by their
known bits);y + k,
k + y, y - k or y itself from the instruction that makes it, (y + k1) - (y + k2) is k1 - k2. The
instruction that makes an operand counts only undecorated;&& or || of two tests against zero where one implies the other: p && q is p and p || q is q when
p implies q. A test is s != 0 or s == 0, the zero on either side, or the ! of one; s != 0 implies
t != 0 when every bit of s that may be 1 is a bit of t: s is t, an & of t, t an | of s, or s an
& and t an | of one operand; s == 0 implies t == 0 the other way round;x + 0, x - 0, x | 0, x ^ 0, a shift by 0, x * 1, x & x, x | x,
true && x, false || x, x && x, x || x, with the constant on either side of what commutes (x & ~0 by its
known bits);OpSelect whose condition is a constant or whose two values are one id, and an OpBitcast to
the type its operand has, or of a bitcast from that type.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.