A deep dive into LLVM's optimization pipeline using two concrete C++ examples: modular increment and endianness conversion. Explores how passes like InstCombine, AggressiveInstCombine, DAGCombiner, and CodeGenPrepare interact, how pass ordering affects results, and how small source changes (using `[[assume]]`, templates, auxiliary variables) can dramatically alter which optimization paths are triggered. Demonstrates both the power and the surprising limitations of modern compiler optimizers, with practical takeaways on writing compiler-friendly code.

26m read timeFrom hmpcabral.com
Post cover image
Table of contents
IntroductionCase 1: Modular incrementCase 2: Endianness conversionConclusionAppendix: other resources

Sort: