frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Why SSA Compilers?

https://mcyoung.xyz/2025/10/21/ssa-1/
65•transpute•3h ago

Comments

rdtsc•2h ago
I like the style of the blog but a minor nit I'd change is have a definition what SSA is right at the top. It discusses SSA for quite a while "SSA is a property of intermediate representations (IRs)", "it's frequently used" and only 10 paragraphs down actually defines what SSA is

> SSA stands for “static single assignment”, and was developed in the 80s as a way to enhance the existing three-argument code (where every statement is in the form x = y op z) so that every program was circuit-like, using a very similar procedure to the one described above.

I understand it's one of those "well if you don't know what it is, the post is not for you" but I think it's a nice article and could get people who are not familiar with the details interested in it

> The reason this works so well is because we took a function with mutation, and converted it into a combinatorial circuit, a type of digital logic circuit that has no state, and which is very easy to analyze.

That's an interesting insight, it made sense to me. I only dealt with SSA when decompiling bytecode or debugging compiler issues, and never knew why it was needed, but that sort of made it click.

vidarh•2h ago
This post is frankly one of the most convoluted discussions of SSA I've read. There's lots of info there, but I'd frankly suggest going back and look at a paper on implementing it. I think I first came across SSA in a paper adding it to Wirths Oberon compiler, and it was much more accessible.

Edit: It was this paper by Brandis and Mössenböck: https://share.google/QNoV9G8yMBWQJqC82

jhallenworld•2h ago
Also I recommend Bob Morgan's book:

https://turbo51.com/download/Building-an-Optimizing-Compile-...

Rochus•52m ago
Indeed a great book; I even have a paper copy.

The SSA book is also pretty good: https://web.archive.org/web/20201111210448/https://ssabook.g...

mananaysiempre•13m ago
I’ve found the SSA book to be... unforgiving in its difficulty. Not in the sense that I thought it to be a bad book but rather in that I was getting the feeling that a dilettante in compilers like me wasn’t the target audience.
Rochus•7m ago
Like so many compiler books from academia.
jchw•1h ago
Honestly, I think it's just something you either like or don't. If all you were trying to do was understand SSA, I agree this blog post is probably inefficient at that particular task, but often blog posts are entertainment as much as education, so meandering through a bunch of different things along the way is part of the deal. Personally I thought there were a lot of pretty interesting insights that I haven't seen a lot of discussion about in other places, though I will admit I mostly learned about SSA from Wikipedia and from people yelling about compilers online.
Rochus•1h ago
Thanks for the link. Looks like an interesting paper. Here is the original reference: https://dl.acm.org/doi/10.1145/197320.197331.

And here is a better readable postscript version: https://web.archive.org/web/20170706013237/ftp://ftp.ssw.uni...

strbean•2h ago
I learned a bit about SSA in a compiler course. Among many other things, it is crucial for register assignment. You want to know each distinct value that will exist, and the lifetimes of those values, in order to give each a register. Then, if have more distinct values existing at one time than you have registers, you have to push stuff to the stack.
tylerhou•6m ago
It is not critical for register assignment -- in fact, SSA makes register assignment more difficult (see the swap problem; the lost copy problem).

Lifetime analysis is important for register assignment, and SSA can make lifetime analysis easier, but plenty of non-SSA compilers (lower-tier JIT compilers often do not use SSA because SSA is heavyweight) are able to register allocate just fine without it.

tylerhou•13m ago
Here's a concise explanation of SSA. Regular (imperative) code is hard to optimize with because in general statements are not pure -- if a statement has side effects, then it might not preserve the behavior to optimize that statement by, for example:

1. Removing that statement (dead code elimination)

2. Deduplicating that statement (available expressions)

3. Reorder that statement with other statements (hoisting; loop-invariant code motion)

4. Duplicating that statement (can be useful to enable other optimizations)

All of the above optimizations are very important in compilers, and they are much, much easier to implement if you don't have to worry about preserving side effects while manipulating the program.

So the point of SSA is to translate a program into an equivalent program whose statements have as few side effects as possible. The result is often something that looks like a functional program. (See: https://www.cs.princeton.edu/~appel/papers/ssafun.pdf, which is famous in the compilers community.) In fact, if you view basic blocks themselves as a function, phi nodes "declare" the arguments of the basic block, and branches correspond to tailcalling the next basic block with corresponding values. This has motivated basic block arguments in MLIR.

The "combinatorial circuit" metaphor is slightly wrong, because most SSA implementations do need to consider state for loads and stores into arbitrary memory, or arbitrary function calls. Also, it's not easy to model a loop of arbitrary length as a (finite) combinatorial circuit. Given that the author works at an AI accelerator company, I can see why he leaned towards that metaphor, though.

noelwelsh•2h ago
The shocking truth is that SSA is functional! That's right, the compiler for your favourite imperative language actually optimizes functional programs. See, for example, https://www.jantar.org/papers/chakravarty03perspective.pdf. In fact, SSA, continuation passing style, and ANF are basically the same thing.
Chabsff•2h ago
My experience with SSA is extremely limited, so that might be a stupid question. But does that remain true once memory enters the picture?

The llvm tutorials I played with (admittedly a long time ago) made it seem like "just allocate everything and trust mem2reg" basically abstracted SSA pretty completely from a user pov.

pizlonator•1h ago
No they're not.

The essence of functional languages is that names are created by lambdas, labmdas are first class, and names might not alias themselves (within the same scope, two references to X may be referencing two instances of X that have different values).

The essence of SSA is that names must-alias themselves (X referenced twice in the same scope will definitely give the same value).

There are lots of other interesting differences.

But perhaps the most important difference is just that when folks implement SSA, or CPS, or ANF, they end up with things that look radically different with little opportunity for skills transfer (if you're an SSA compiler hacker then you'll feel like a fish out of water in a CPS compiler).

Folks like to write these "cute" papers that say things that sound nice but aren't really true.

zozbot234•12m ago
The whole ad-hoc mechanism of phi-nodes in SSA can be replaced by local blocks with parameters. A block that can take parameters is not that different conceptually from a lambda.
aatd86•1h ago
The same thing I don't know... but a long time ago, I remember reading that SSA and CPS were isomorphic. Basically CPS being used for functional languages.

edit: actually even discussed on here

CPS is formally equivalent to SSA, is it not? What are advantages of using CPS o... | Hacker News https://share.google/PkSUW97GIknkag7WY

mbauman•1h ago
Forget compilers, SSA is an immensely valuable readability improvement for humans, too.
zachixer•1h ago
Every time I see a clean SSA explainer like this, I’m reminded that the “simplicity” of SSA only exists because we’ve decided mutation is evil. It’s not that SSA is simpler — it’s that we’ve engineered our entire optimization pipeline around pretending state doesn’t exist.

It’s a brilliant illusion that works… until you hit aliasing, memory models, or concurrency, and suddenly the beautiful DAG collapses into a pile of phi nodes and load/store hell.

vidarh•59m ago
SSA is appealing because you can defer the load/store hell until after a bunch of optimizations, though, and a lot of those optimizations becomes a lot easier to reason about when you get to pretend state doesn't exist.
achierius•57m ago
You have it backwards. Modern compilers don't use SSA because it's "simpler", we use it because it enables very fast data-flow optimizations (constant prop, CSE, register allocation, etc.) that would otherwise require a lot of state. It doesn't "pretend state doesn't exist", it's actually exactly what makes it possible/practical for the compiler to handle changes in state.

As some evidence to the second point: Haskell is a language that does enforce immutability, but it's compiler, GHC, does not use SSA for main IR -- it uses a "spineless tagless g-machine" graph representation that does, in fact, rely on that immutability. SSA only happens later once it's lowered to a mutating form. If your variables aren't mutated, then you don't even need to transform them to SSA!

Of course, you're welcome to try something else, people certainly have -- take a look at how V8's move to Sea-of-Nodes has gone for them.

antonvs•3m ago
> take a look at how V8's move to Sea-of-Nodes has gone for them.

Are you implying it hasn't gone well? I thought it bought some performance at least. What are the major issues? Any sources I can follow up on?

toast0•37m ago
> pretending state doesn’t exist.

As a fan of a functional language, immutability doesn't mean state doesn't exist. You keep state with assignment --- in SSA, every piece of state has a new name.

If you want to keep state beyond the scope of a function, you have to return it, or call another function with it (and hope you have tail call elimination). Or, stash it in a mutable escape hatch.

rpearl•17m ago
SSA form is a state representation. SSA encodes data flow information explicitly which therefore simplifies all other analysis passes. Including alias analysis.
antonvs•15m ago
> the “simplicity” of SSA only exists because we’ve decided mutation is evil.

Mutation is the result of sloppy thinking about the role of time in computation. Sloppy thinking is a hindrance to efficient and tractable code transformations.

When you "mutate" a value, you're implicitly indexing it on a time offset - the variable had one value at time t_0 and another comment value at time t_1. SSA simply uses naming to make this explicit. (As do CPS and ANF, which is where that "equivalence" comes from.)

If you don't use SSA, CPS, or ANF for this purpose, you need to do something else to make the time dimension explicit, or you're going to be dealing with some very hairy problems.

"Evil" in this case is shorthand for saying that mutable variables are an unsuitable model for the purpose. That's not a subjective decision - try to achieve similar results without dealing with the time/mutation issue and you'll find out why.

jcranmer•8m ago
SSA isn't about saying mutation is evil. It's about trivializing chasing down def-use rules. In the Dragon Book, essentially the first two dataflow analyses introduced are "reaching definitions" and "live variables"; within an SSA-based IR, these algorithms are basically "traverse a few pointers". There's also some ancillary benefits--SSA also makes a flow-insensitive algorithm partially flow-sensitive just by the fact that it's renaming several variables.

Sure, you still need to keep those algorithms in place for being able to reason about memory loads and stores. But if you put effort into kicking memory operations into virtual register operations (where you get SSA for free), then you can also make the compiler faster since you're not constantly rerunning these analyses, but only on demand for the handful of passes that specifically care about eliminating or moving loads and stores.

KeplerBoy•1h ago
Smallest of nitpicks: the depicted multiplier is a 2 bit multiplier. A one bit multiplier is just an and gate.
pubby•41m ago
I like this article a lot but it doesn't answer the question of "Why SSA?".

Sure, a graph representation is nice, but that isn't a unique property of SSA. You can have graph IRs that aren't SSA at all.

And sure, SSA makes some optimizations easy, but it also makes other operations more difficult. When you consider that, plus the fact that going into and out of SSA is quite involved, it doesn't seem like SSA is worth the fuss.

So why SSA?

Well, it turns out compilers have sequencing issues. If you view compilation as a series of small code transformations, your representation goes from A -> B, then B -> C, then C -> D and so on. At least, that's how it works for non-optimizing compilers.

For optimizing compilers however, passes want to loop. Whenever an optimization is found, previous passes should be run again with new inputs... if possible. The easiest way to ensure this is to make all optimizations input and output the same representation. So A -> B is no good. We want A -> A: a singular representation.

So if we want a singular representation, let's pick a good one right? One that works reasonably well for most things. That's why SSA is useful: it's a decently good singular representation we can use for every pass.

ivanjermakov•30m ago
Static single assignment (SSA)

Ovi: Twin backbone cross-modal fusion for audio-video generation

https://github.com/character-ai/Ovi
207•montyanderson•3h ago•62 comments

Willow quantum chip demonstrates verifiable quantum advantage on hardware

https://blog.google/technology/research/quantum-echoes-willow-verifiable-quantum-advantage/
345•AbhishekParmar•7h ago•161 comments

JMAP for Calendars, Contacts and Files Now in Stalwart

https://stalw.art/blog/jmap-collaboration/
209•StalwartLabs•5h ago•84 comments

Mass Assignment Vulnerability Exposes Max Verstappen Passport and F1 Drivers PII

https://ian.sh/fia
184•galnagli•4h ago•45 comments

Why SSA Compilers?

https://mcyoung.xyz/2025/10/21/ssa-1/
65•transpute•3h ago•28 comments

Scripts I wrote that I use all the time

https://evanhahn.com/scripts-i-wrote-that-i-use-all-the-time/
378•speckx•8h ago•133 comments

Element: setHTML() method

https://developer.mozilla.org/en-US/docs/Web/API/Element/setHTML
84•todsacerdoti•14h ago•35 comments

VortexNet: Neural network based on fluid dynamics

https://github.com/samim23/vortexnet
4•vegax87•23m ago•0 comments

Rivian's TM-B electric bike

https://www.theverge.com/news/804157/rivian-tm-b-electric-bike-price-specs-helmet-quad
102•hasheddan•5h ago•171 comments

InpharmD (YC W21) Is Hiring – NLP Engineer

https://inpharmd.com/jobs/inpharmd-is-hiring-ai-ml-engineer
1•tulasichintha•2h ago

Common yeast can survive Martian conditions

https://phys.org/news/2025-10-common-yeast-survive-martian-conditions.html
31•geox•1w ago•13 comments

YASA beats own power density record pushing electric motor to 59kW/kg benchmark

https://yasa.com/news/yasa-smashes-own-unofficial-power-density-world-record-pushing-state-of-the...
13•breve•2h ago•1 comments

Karpathy on DeepSeek-OCR paper: Are pixels better inputs to LLMs than text?

https://twitter.com/karpathy/status/1980397031542989305
65•JnBrymn•1d ago•14 comments

Show HN: Cuq – Formal Verification of Rust GPU Kernels

https://github.com/neelsomani/cuq
27•nsomani•3h ago•21 comments

MinIO stops distributing free Docker images

https://github.com/minio/minio/issues/21647#issuecomment-3418675115
637•LexSiga•16h ago•376 comments

HP SitePrint

https://www.hp.com/us-en/printers/site-print/layout-robot.html
137•gjvc•5h ago•99 comments

Google flags Immich sites as dangerous

https://immich.app/blog/google-flags-immich-as-dangerous
19•janpio•2h ago•3 comments

Iceland reports the presence of mosquitoes as climate warms

https://www.npr.org/2025/10/22/nx-s1-5582748/iceland-mosquitoes-first-time
30•sans_souse•59m ago•1 comments

Criticisms of “The Body Keeps the Score”

https://josepheverettwil.substack.com/p/the-body-keeps-the-score-is-bullshit
172•adityaathalye•4h ago•170 comments

I, Sharpie

https://www.commonplace.org/p/chris-griswold-i-sharpie
11•delichon•6d ago•6 comments

Rethinking CQRS: An Interview on OpenCQRS

https://docs.eventsourcingdb.io/blog/2025/10/23/rethinking-cqrs-an-interview-on-opencqrs/
13•goloroden•2h ago•0 comments

I see a future in jj

https://steveklabnik.com/writing/i-see-a-future-in-jj/
177•steveklabnik•5h ago•104 comments

Vertiginous Accounts: Travels in the Air (1871 edition)

https://publicdomainreview.org/collection/travels-in-the-air/
4•prismatic•16h ago•0 comments

The Tonnetz

https://thetonnetz.com/
39•mci•4d ago•7 comments

Enchanting Imposters

https://daily.jstor.org/enchanting-imposters/
4•Petiver•16h ago•0 comments

Cryptographic Issues in Cloudflare's Circl FourQ Implementation (CVE-2025-8556)

https://www.botanica.software/blog/cryptographic-issues-in-cloudflares-circl-fourq-implementation
137•botanica_labs•8h ago•66 comments

LibCube: Find new sounds from audio synths easier

https://github.com/cslr/libcube-public/wiki
6•cslr•4d ago•1 comments

Galaxy XR: The first Android XR headset

https://blog.google/products/android/samsung-galaxy-xr/
141•thelastgallon•6h ago•164 comments

Linux Capabilities Revisited

https://dfir.ch/posts/linux_capabilities/
160•Harvesterify•9h ago•32 comments

Meta is axing 600 roles across its AI division

https://www.theverge.com/news/804253/meta-ai-research-layoffs-fair-superintelligence
425•Lionga•6h ago•349 comments