spv_opt_values takes out an instruction that computes what an instruction dominating it already computed, and
makes everything that read its result read the other's (spirv-opt's local and global redundancy elimination). Two
instructions are equal when their opcode, type, operands and decorations are; the two operands of an integer or
logical instruction that commutes (OpIAdd, OpIMul, the bitwise ones, OpIEqual, OpINotEqual, the logical
ones) may be in either order. Float arithmetic is equal only as written.
What it numbers:
OpImageQueryLod, the derivatives), since a block under a branch does not have the derivatives of the block that
dominates it, and an OpSampledImage, which only its own block may use;BufferBlock may
write under Uniform, so its Uniform loads follow the second rule.It finds each function's dominators (Cooper, Harvey and Kennedy) and then walks the instructions once, in the module's order, where a block comes after the blocks that dominate it: each instruction's operands are replaced as it is reached, then it is looked up in one table of the instructions kept so far, where an entry counts when its block dominates this one. A phi that read a replaced result around a loop is fixed at the end.
What it leaves alone: an instruction of an opcode it has no layout for, with every result such an instruction's words
might name; a result with a decoration that has operands; OpUndef, OpPhi, OpImageRead and
OpImageTexelPointer; and a whole module that has both a 64-bit integer type and an OpSwitch, whose cases would be
three words each.
On the Maxwell translator's modules it removes the access chains, bitcasts, negations and field extracts a block repeats, and the second load of a constant buffer word or an input.
Made from docs/layers/gpu/spirv-opt.md at 69237645142c. GPL-3.0-or-later.