pub fn fuse_linear(graph: &SharedGraph, roots: &[NodeId]) -> usizeExpand description
Fuse MatMul → Add(rank-1 bias) patterns into Op::FusedLinear
(Phase 6d Track 3). Walks the graph; for each Add whose LHS is
a MatMul and whose RHS is a rank-1 bias whose length equals the
matmul output’s last dim, emits a fresh FusedLinear node and
remaps consumers of the Add to it.
Conservative: only fires when the Add is the sole consumer of
the MatMul. Otherwise we’d be creating a duplicate matmul
computation. CSE doesn’t help here because MatMul and
MatMul-inside-FusedLinear aren’t structurally equal at the IR
level — backends with truly fused kernels are the ones that
benefit, so we’d rather skip the fusion than waste the work.
Returns the count of fusions applied.