A new pass, spirv/hoist, runs after the roll pass. It moves a load out of every loop it is
invariant in, into the loop's preheader, in original order and inner loops first. The pure value
ops its indices need move with it. A load qualifies only when all of the following hold:
- It is not volatile and does not make memory visible.
- It goes through an access chain rooted at a Uniform-class Block view. ModuleBuilder declares
those only for a read-only slot with a bounded window, on a profile whose containment emits no
check; it refuses a Uniform resource that is not a Block, so no BufferBlock view exists.
- Every index is defined outside the loop, or computed inside it only by pure value ops of
invariant operands.
A loop is a candidate only where no buffer write can run in any block from which its header is
reachable: the body, what runs before the loop, and an enclosing loop's later code through its
back edge. A buffer write is a store, atomic or image write through StorageBuffer,
PhysicalStorageBuffer or Uniform memory, or a call to a function containing one. Inside a routine,
a loop is a candidate only where the module writes no buffer at all. This also covers another
invocation's write that a barrier inside the loop would make visible.
Speculation: a load in the loop's header block runs whenever the loop is entered, so it moves on
every profile. A load in any other loop block moves only under containment with robust buffer
access (robustBufferAccess or robustBufferAccess2): a uniform view carries no in-shader check to
bypass, and robust access answers in range or zero past the bound range. Under
ContainmentPolicy::UnsafeOff only header-block loads move. Every decision comes from storage
class, view kind, operand definitions, the loop metadata, CFG reachability and the profile's
containment. The values are the same, so the pass is exact and has no FAST-PATHS row.
docs/ARCHITECTURE.md names it in the spirv row and the tidy stage.
Verified (ftk2, 6d6add9acf on 73caf92102):
- The 4 hoist unit tests plus the engine test pass (27487). The engine test reads an authored
constant struct at fixed words, each under a per-trip branch, in a loop. On all 4 robust
access-test profiles: the slot is Descriptor(UniformWords), the loop holds no Uniform-class
load, and the interpreter's sums are right for n = 0, 1, 2, 5, 8. Negative control: with the
hoist call removed, the test fails ("moltenvk-m3: loads of in in the loop").
- Suite: 3572/3573. The one failure is golden_hashes: 19 cells, engine/tns_mm_flags on the 19
robust profiles, re-blessed on development. clippy all-features, m2v_gpu and m2v_cpu_icd 0;
rustdoc 0 (27513-27517).
- Authored compile census (27501, M3): 0 failed, 0 differences, 0 regressions, 768 artifacts
moved. Slowest compile 590 ms. Peak per-case worker 392 MB, against 391 before.
- Registers on the real modules:
- RADV XTX: VGPRs 48 both ways, SGPRs 108, no spills, scratch 0, 32 subgroups per SIMD both
ways; latency -29% (c4) and -26% (c6_8).
- NVIDIA 2080: registers 64 -> 62 (c4_0, c4_3) and 64 -> 64 (c6_8), stack 0.
- Release timings, cold, one run each, GPU median of 21 CBs at K=1, before -> after in us:
- The face-tracking conv kernels through the runtime, device-local:
- XTX: c4_0 22.7 -> 20.8, c4_3 18.3 -> 17.2, c6_8 160.3 -> 133.9 (-16%).
- 2080: c4_0 29.2 -> 26.7, c6_8 107.9 -> 103.2.
- One interleaved bare A/B on the 2080 (27567, 6 pairs, P0): the hoist is faster in 5 of 6
pairs, by 0.8% to 3.7%.
- Cold "state made in" is unchanged: XTX 8.4-12.1 ms and 2080 20-71 ms in both builds.
SEMANTICS_VERSION 2103 -> 2104.