diff --git a/crates/metal2vulkan-air/src/canon/const_hoist.rs b/crates/metal2vulkan-air/src/canon/const_hoist.rs
new file mode 100644
index 000000000..50a0312ea
--- /dev/null
+++ b/crates/metal2vulkan-air/src/canon/const_hoist.rs
@@ -0,0 +1,394 @@
+//! A kernel's plain loads of its constant references, made in its entry block.
+//!
+//! A kernel often reads a `constant T&` parameter only behind its bounds branch (`if (gid >= n)
+//! return; out[gid] = in[gid] * scale;`): the load of `scale` lies in a block the threads past the
+//! end skip. [`expand`] moves each such load into the entry block, ahead of every branch, its value
+//! reaching each use by dominance, where all of the following hold. Each is read from the body's
+//! structure and the entry's ABI, never from a name.
+//!
+//! - **A plain load of a scalar or vector.** Neither volatile nor atomic, of an integer, a float or
+//! a vector of them. The load of a pointer or an aggregate stays.
+//! - **The reference's own bytes, at an offset fixed at translation time.** Its address is a
+//! parameter the ABI binds as a buffer of the constant address space with a stated
+//! `air.buffer_size` (a `constant T&`; no function constant gates it), or that parameter plus
+//! `getelementptr`s at constant, non-negative indices and bitcasts, which move with the load. The
+//! bytes read lie inside the referenced object, `[0, air.buffer_size)`. The address is then one
+//! address for every thread of the dispatch, and each form of the access contains it at the
+//! entry as it did where it stood: the same slot, a bound storage view under its robust buffer
+//! access, or a device address read at a constant offset inside the object, which no check
+//! clamps in either place. A pointer parameter (`constant T*`, no size), an offset outside the
+//! object, and an offset the run computes stay.
+//! - **No write before it.** 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 a call of any kind but arithmetic, conversions, group
+//! operations, built-in reads and texture reads and queries. A device buffer may cover the
+//! constant buffer's bytes, so such a write could change what the load reads.
+//!
+//! Anything else stays where it is. The moved load reads the bytes it read where it stood: a
+//! thread that skipped its block reads them too and uses nothing of them.
+
+use std::collections::BTreeMap;
+
+use crate::abi::{ParamBinding, ParamRole};
+use crate::budget::Meter;
+use crate::error::Error;
+use crate::intrinsics::{AirIntrinsic, LlvmIntrinsic, TexOp};
+use crate::ir::{AddrSpace, BlockId, Body, Callee, CastOp, FuncId, Idx, InstId, InstKind};
+use crate::ir::{Layout, ModuleParts, Type, TypeId, TypeLayouts, TypeTable, Value};
+
+use super::pieces::gep_offset;
+use super::rewrite::{apply, filled, invariant, scoped, BodyEdit};
+
+/// The address steps a load's address is followed through to its parameter.
+const STEPS: usize = 64;
+
+/// Make in the entry block each load of `func`'s body that reads a constant reference the
+/// entry's `bindings` bind, where nothing before it may write device memory (the module docs).
+pub(super) fn expand(
+ body: Body,
+ parts: &ModuleParts,
+ func: FuncId,
+ bindings: &[ParamBinding],
+ m: &mut Meter,
+) -> Result
{
+ let f = parts
+ .funcs
+ .get(func)
+ .ok_or_else(|| invariant("entry out of range"))?;
+ let Some(Type::Function { params: tys, .. }) = parts.types.get(f.ty) else {
+ return Err(invariant("the entry's type is not a function"));
+ };
+ let objects: BTreeMap = bindings
+ .iter()
+ .filter_map(|b| reference(b, tys, &parts.types))
+ .collect();
+ if objects.is_empty() {
+ return Ok(body);
+ }
+ m.charge(objects.len() * std::mem::size_of::<(u32, u64)>() * 2)?;
+ let next = scoped(m, |m, held| {
+ let cx = Cx {
+ body: &body,
+ parts,
+ tys,
+ objects: &objects,
+ };
+ let moved = cx.moves(m, held)?;
+ if moved.is_empty() {
+ return Ok(None);
+ }
+ let mut edit = BodyEdit::keep_all(&body, m, held)?;
+ edit.moved = moved;
+ apply(&body, &edit, &|c| c, m).map(Some)
+ });
+ m.release(objects.len() * std::mem::size_of::<(u32, u64)>() * 2);
+ match next? {
+ Some(next) => {
+ body.release(m);
+ Ok(next)
+ }
+ None => Ok(body),
+ }
+}
+
+/// The parameter `b` binds and the bytes of the object it references, where it is a constant
+/// reference: a buffer of the constant address space with a stated `air.buffer_size`, which no
+/// function constant gates, of a constant-space pointer type in `tys`.
+fn reference(b: &ParamBinding, tys: &[TypeId], types: &TypeTable) -> Option<(u32, u64)> {
+ let ParamRole::Buffer(arg) = &b.role else {
+ return None;
+ };
+ if b.unused || b.predicate.is_some() || arg.space != AddrSpace::Constant {
+ return None;
+ }
+ let ty = types.get(*tys.get(usize::try_from(b.param).ok()?)?)?;
+ let pointer = matches!(
+ ty,
+ Type::Ptr {
+ space: AddrSpace::Constant
+ }
+ );
+ pointer.then_some((b.param, u64::from(arg.buffer_size?)))
+}
+
+/// What the walk reads.
+struct Cx<'a> {
+ body: &'a Body,
+ parts: &'a ModuleParts,
+ /// The entry's parameter types.
+ tys: &'a [TypeId],
+ /// The constant references: parameter, and the bytes of the object it references.
+ objects: &'a BTreeMap,
+}
+
+impl Cx<'_> {
+ /// The loads to make in the entry block, each with the address steps it moves with, mapped to
+ /// the entry block. Its tables are charged to `held`.
+ fn moves(&self, m: &mut Meter, held: &mut usize) -> Result, Error> {
+ let mut moved = BTreeMap::new();
+ let n = self.body.blocks.len();
+ let entry = BlockId::new(0);
+ if n < 2 {
+ return Ok(moved);
+ }
+ // The blocks the entry reaches, and those a write may precede: every block a block that
+ // writes leads to.
+ let mut reached = filled(m, held, n, false)?;
+ let mut written = filled(m, held, n, false)?;
+ let mut stack: Vec = filled(m, held, n, entry)?;
+ stack.clear();
+ if let Some(r) = reached.get_mut(entry.index()) {
+ *r = true;
+ }
+ stack.push(entry);
+ while let Some(b) = stack.pop() {
+ m.tick(1)?;
+ for s in self.body.successors(b) {
+ // A branch back to the entry block: it is no place every path starts from.
+ if s == entry {
+ return Ok(moved);
+ }
+ if let Some(r) = reached.get_mut(s.index()).filter(|r| !**r) {
+ *r = true;
+ stack.push(s);
+ }
+ }
+ }
+ for (b, _) in self.body.blocks.iter() {
+ m.tick(1)?;
+ if !self.body.block_insts(b).any(|(_, i)| self.writes(&i.kind)) {
+ continue;
+ }
+ stack.push(b);
+ while let Some(b) = stack.pop() {
+ m.tick(1)?;
+ for s in self.body.successors(b) {
+ if let Some(w) = written.get_mut(s.index()).filter(|w| !**w) {
+ *w = true;
+ stack.push(s);
+ }
+ }
+ }
+ }
+ let mut layouts = None;
+ for (b, _) in self.body.blocks.iter().skip(1) {
+ let mut clean = reached.get(b.index()).copied().unwrap_or(false)
+ && !written.get(b.index()).copied().unwrap_or(true);
+ for (id, inst) in self.body.block_insts(b) {
+ m.tick(1)?;
+ if !clean {
+ break;
+ }
+ if self.writes(&inst.kind) {
+ clean = false;
+ continue;
+ }
+ let InstKind::Load {
+ ptr,
+ volatile: false,
+ atomic: None,
+ ..
+ } = inst.kind
+ else {
+ continue;
+ };
+ if !self.plain_value(inst.ty) {
+ continue;
+ }
+ if layouts.is_none() {
+ let l = TypeLayouts::new(&self.parts.data_layout, &self.parts.types, m)?;
+ *held = held.saturating_add(
+ self.parts.types.len() * std::mem::size_of::