A kernel often reads a constant T& parameter only behind its bounds branch
(if (gid >= n) return; out[gid] = in[gid] * scale;). canon::const_hoist
moves each such load into the entry block, its value reaching its uses by
dominance, where all of these hold, each read from the body's structure and
the entry's ABI:
- a plain load (not volatile, not atomic) of an integer, a float or a vector
of them; a pointer's or an aggregate's load stays;
- its address is a parameter the ABI binds as a constant-space buffer with a
stated air.buffer_size and no function-constant predicate (a constant T&),
or that parameter plus GEPs at constant, non-negative indices and bitcasts,
which move with it; the bytes read lie inside [0, air.buffer_size). The
address is then one address for every thread, and each form contains it at
the entry as where it stood: the same slot, a bound storage view under its
robust buffer access, or a device address at a constant offset, which no
check clamps in either place. A constant T* (no size), an offset past the
object and an offset the run computes stay;
- no instruction on any path from the function's start to the load may write
device memory or order another thread's writes before it: a store or
memory intrinsic whose destination is not thread or threadgroup memory, an
atomic or atomic load of any space, a fence or barrier, a texture write,
or any call but arithmetic, conversions, group operations, built-in reads
and texture reads and queries. A forward reach from every writing block
marks the blocks a write may precede; a load's own block counts up to it.
Where it lives: a new canon pass beside speculate, not inside it.
speculate.rs is a fidelity pass: it gives Metal's measured if-conversion of
group operations, keyed by Metal's budgets, and its moves change what a
program observes. This one changes nothing a program observes and its rule
is soundness alone (no write before, the access contained), so it has no
place in speculate's measured decisions; it shares rewrite::BodyEdit's moves
with it. It runs after aggregates::expand, so an aggregate load of a
reference, split into its members' loads, moves too, and before the
OpenCL hidden buffers and the program-scope bindings add parameters. Kernels
only: the measured kernels are compute kernels.
The planner's measurement (the audit seat's lab pass, which moved every load
at a constant parameter itself) on the compute benchmark's guest kernels FM
copy, FM vertical and Fluid's pressure step, GPU time of 20 dispatches, arms
alternated, output digests equal in every pair: the RTX 3090 -3.6%, -0.1%,
-9.5%; the RX 7900 XTX -7.3%, -0.7%, -12.2%; the Iris Xe +0.4%, 0.0%,
0.0%. On the Iris, ANV sinks the loads back into the branches: FM copy's
compiled code goes from 134 to 132 instructions (1026 to 912 cycles), its 8
SENDs unchanged (read from INTEL_DEBUG=cs, not from Mesa's source).
SEMANTICS_VERSION 2386 -> 2387: a kernel whose constant-reference loads move
translates to other words.
Verified: pending the green job.