r/Compilers • • 8d ago

Performance of a formally-verified C compiler vs. gcc -O2

https://ut-infraai.github.io/2026/11/13/trying-to-make-compcert-as-fast-as-gcc-o2/
29 Upvotes

5 comments sorted by

7

u/flatfinger 7d ago

For many tasks, a 28% penalty to limit many actions' side effects to those implied by the underlying platform would seem a cost worth paying. Proving that no individual actions within a program would be capable of violating memory safety invariants unless they have already been violated can be greatly facilitated if the number of individual actions that are capable of violating memory safety invariants is limited. Allowing memory safety to be breached by an otherwise-benign data race, the multiplication of two uint16_t values, or the execution a side-effect-free loop whose exit condition isn't proven to always be satisfiable, complicates such proofs (and in some cases may make them impossible).

2

u/marshaharsha 6d ago

Really cool article. I had never thought of the possibility of not proving a given optimization correct, but proving instead that each individual output program had the same semantics as the input program. 

1

u/corisian 3d ago

In the process of proving semantic preservation you essentially prove the individual (optimization) passes correct. The notion of **correct optimization** should be that the optimized program **behaves equivalent** to the original one.

2

u/marshaharsha 3d ago

I can’t tell if you’re saying the same thing I am. Rephrasing what I’m saying: I had always assumed that the only notion of “proving correctness” of an optimization Optim was to prove this universally quantified claim: For every program p, Equiv(p), where Equiv means Semantics(p) = Semantics(Optim(p)). But there is another possibility, one that never proves Optim correct in general. Instead, for an individual program p_1, and for the next program p_2, and for any enumerated finite set of programs, you prove Equiv(p_i), but you never do the “for every” aspect, and you never even write a general proof for the finite set. So you’ve proven correctness only for the finite set, element by element. In return for the much weaker result, all you need to write is the equivalence checker. The “optimization pass” could even be random mutation of tokens, as long as you can tolerate a lot of falses from the equivalence checker. 

2

u/corisian 3d ago

Ah I see. I did indeed misunderstand you. You were talking about translation validation.

As a side note, the equivalence checker is still tuned to the specific pass of the compiler. E.g., in the article they mention register allocation. There, they actually had a verified allocator, but opted for the translation validation in the end for performance reasons. The main difficulty of the original proof, was not the logic, but the termination of the algorithm.