Two studies in compiler optimisations

A walkthrough of how LLVM optimises two small C++ functions, with source excerpts and exercises.

Author
Henrique Cabral
Published
20 March 2026
Kind
Personal blog post with annotated compiler output and exercises
Original
www.hmpcabral.com/2026/03/20/two-studies-in-compiler-optimisations/
Subject
Compilers and interpreters
Themes
Close to the machine, Getting good

What it is

Henrique Cabral wrote a blog post that explains LLVM internals through two examples. One is a modular increment for round-robin indexing. The other is converting bytes to an integer with a chosen byte order. The aim is to show how small source changes change the compiler path.

What it says

What evidence it gives

The post shows assembly output for each variant, intermediate-code diffs, and excerpts from LLVM source. It names the pass behind each change. It gives no timing benchmarks. Its one cost figure is a division latency on one Intel core.

Interests and limits

The author is an independent blogger with no stated commercial interest. All results use one LLVM version, 22.1.0, on x86-64. Other compilers are only mentioned, and gcc is said not to fold the loads. Behaviour in other versions and targets was not tested. The conclusions are advice, not measured speed-ups.