Ever since I have been coding agentically the last few months, looking less and less at the actual code, I have been looking to better understand my relationship with code itself.
I seem to still “prefer” language implementations because I steer the agents through them, using the language as a scaffold for reasoning and communication.
Does it even matter? I know it’s an overused analogy but I don’t care about which instructions the compilers emit, as long as the meaning is preserved and performance is acceptable.
I tried taking this to an extreme: I wanted to see if I could work entirely with the low-level representation, bypassing human-readable languages altogether.
In my last post I built borrIR, a borrow checker and toolchain for raw LLVM IR.
Most of the motivation was pure commitment to agentic programming: if our dutiful clankers are writing all the code anyway, why keep a human-facing front-end?
Beyond the sensationalized motivation, I had a deeper gut feeling that there could be a benefit to working directly with a lower-level representation of code.
Have you tried to code in OCaml or Haskell? It’s wonderful but it definitely requires more cognitive effort to keep track of all the types and abstractions in your head.
Could the same be true for our clankers?
Are all tokens of equal density in the context?
In 2013 a team at Google published word2vec. It turns every word into a vector, a list of numbers learned from the company the word keeps. By treating words as vectors, we can perform arithmetic on their meanings and discover relationships between them:
This continues to be my basic understanding of how LLMs work. An LLM still starts this way. Every token is looked up in a table and comes out as one vector.
In our embeddings not all vectors are equally informative. Some words have dense, specific representations, while others are more diffuse and context-dependent. Take queen for example: its vector is highly specific and informative whereas bank is more ambiguous and context-dependent. One vector has to cover multiple senses, so the model relies on the surrounding context to disambiguate it.
The same is true for mutable variables.
When variable names are reused for different values, the model has to rely on context to disambiguate them, just like it does with polysemous words in natural language.
Compilers face a similar challenge when reasoning about programs with mutable variables, and by and large, gave up. GCC, LLVM, Go, V8 and HotSpot all lower your program into static single assignment before they try to reason about it.
Tip In SSA every value gets one name, once. Nothing is mutated in place and nothing shadows an outer variable. A name means the same thing everywhere it appears.
If mutable assignments are hard for compilers to reason about, they are likely hard for LLMs to reason about as well.
This is my hypothesis: LLMs will find SSA-style code easier to reason about than code with mutable variables.
§Does an LLM read IR better than Rust?
The evaluation setup was designed to test whether LLMs find SSA-style code easier to reason about than code with mutable variables. In order to make a fair comparison, each program was written in three different notations:
- Mutable Rust: ordinary Rust with
let mutand reassignment. - Single-assignment Rust: the same Rust, with a fresh name for every new value.
- LLVM IR: the compiled SSA form of the mutable Rust.
I generated 40 different small programs. Each one threads three variables through eight
steps of branches and helper calls, and each one exists in three notations
that return the same value:11Compiled with rustc -C opt-level=0 followed by opt -passes=sroa,mem2reg,instnamer.
Each variant was given to Claude Haiku with every tool turned off and asked
the same question: what integer does target(seed) return?
The program was then made intentionally more complex with clutter that does not affect the final result: inner blocks that shadow variables, dead branches, and decoy functions.
The smaller model struggled more with the mutable Rust notation, making more mistakes and showing a clearer benefit from the SSA form in single-assignment Rust or LLVM IR.
Turns out that the clutter made no difference for the model’s performance on mutable Rust. The accuracy remained around 80% regardless of the amount of clutter and the failure was on account of the similarity between consecutive steps, which made it easy to confuse the current value of a variable with its previous value.
That is the whole raison d’être of single-assignment Rust and SSA: each value gets a fresh name, so there is no ambiguity.
Here are two consecutive steps from one of the programs:
if acc > aux {
acc = helper_1(acc, aux);
tag = tag.wrapping_add(1);
} else {
aux = aux.wrapping_sub(18);
acc = (acc.wrapping_add(aux ^ 14)) & 2047;
}
if acc > aux {
acc = helper_1(acc, aux);
tag = tag.wrapping_add(8);
} else {
aux = aux.wrapping_sub(14);
acc = (acc.wrapping_add(aux ^ 2)) & 2047;
}
The density of assignments to acc is high, which increases the likelihood of confusion between consecutive steps along with the
complexity of the expressions on the right-hand side, which makes it easy to lose track of which value belongs to which step.
acc = (acc.wrapping_add(aux ^ 14)) & 2047; is an add, an xor, a mask and a write. IR puts one operation on each line.
This needs a lot more lines to represent the same computation but it makes each step unambiguous and easier for the model to track.
At the scale of my evaluation, a larger model does handle the ambiguity better but a larger benchmark would likely reveal the limits of even larger models, especially as the programs grow in complexity and the density of assignments increases.
The main downside of raw IR is verbosity, but this verbosity is exactly what helps the model avoid confusion between consecutive steps.
The disparity between the two implementations in token output seems to diminish over time. Confused? So was I.
I gave both Claude Haiku and Claude Sonnet the same tiny starter program in
Rust and in borrIR (raw zero-libc LLVM IR), then asked for 10 cumulative
features in a row.22Both Haiku and Sonnet achieved a perfect score of 10/10 on the first try with zero regressions in raw LLVM IR.
In a standalone file, raw LLVM IR is 3–5× more verbose than Rust. After multiple sequential feature turns, however, the overhead diminishes: 1.15× on Sonnet and 1.49× on Haiku.
Haiku finished the LLVM IR session 30 seconds faster than the
Rust one (174s vs. 205s) as the cherry on top.
Maybe the downside is not as significant as it initially appears, at least for writing code.
There is something here that I will continue to ponder. Just because LLMs are approaching super-intelligence does not preclude them from benefiting from simpler representations like SSA. The Dunning-Kruger effect is strong for me, so I am usually emboldened to question basic principles and assumptions that others might take for granted.
Another analogy I draw from is how CPUs are able to do incredibly complex computations efficiently by breaking them down into simpler, well-defined micro-operations. We can think of SSA as providing a similar kind of simplification for LLMs when reasoning about code.
My goal is to author the next project purely in LLVM IR and see where it takes me.
In the meantime, be nice to our clankers. Keep it SSA, stupid.