The walk also keeps, for each 32-bit integer value, the bits known 0 and the bits known 1 (LLVM's known bits), two words per id: a constant's are all known; an instruction's come from its operands':
&, |, ^, ~, a select (what both values know) and a bitcast between the two signs, bit by bit;OpIAdd, OpISub and OpSNegate with the carries: a bit is known where both operands' bits and the carry into
it are (LLVM's computeForAddCarry);OpIMul: the low zeros of the two operands add up, and so do their high zeros past 32;OpBitFieldUExtract, OpBitFieldSExtract and
OpBitFieldInsert with a constant offset and count that end by bit 32;What it folds:
((x << 4) + 480 >> 2) & 3 is 0, (x & 0xffff) >> 16 is 0;0 > (x & 0x7fffffff) is false, (x & 0xff) <
256 true; and an operand compared with itself (x < x is false, x <= x true);a & b where every bit of a that may be 1 is known 1 in b, a | b where every bit of b that may be 1 is
known 1 in a, and OpBitFieldUExtract from bit 0 that keeps every bit of its base that may be 1 (signed, one
whose base's bits from its sign bit up are all known alike): each is a.A boolean is known only as a constant, which the folds above take already. The comparisons then fold the selects and logical instructions on them as constants.
On the Maxwell translator's modules it removes the component of an indexed constant buffer read: the translator
splits an address made of a register shifted by 4 plus an offset into a vec4's index and (address >> 2) & 3, and
the low bits of such an address are known. Also the sign tests of masked values (an absolute value or a clamp of what
cannot be negative) and the fields past a value's width.
Made from docs/layers/gpu/spirv-opt.md at 69237645142c. GPL-3.0-or-later.