Chapter 21 Further Reading: Understanding Compiler Output
1. Compiler Explorer (godbolt.org) Matt Godbolt — free web application
The interactive compiler output tool used throughout this chapter. Supports GCC, Clang, MSVC, ICC, and dozens of other compilers; 30+ target architectures; every major compiler version. The "diff" feature, color-coded source mapping, and execution panel (to run the program and verify output) make it indispensable for learning compiler behavior.
2. "What Every C Programmer Should Know About Undefined Behavior" — LLVM Blog Chandler Carruth, Chris Lattner — https://blog.llvm.org
A three-part series explaining how C's undefined behavior rules allow aggressive compiler optimizations, with examples of code that "works at -O0" but generates incorrect assembly at -O2. Directly relevant to reading compiler output and understanding why -O2 looks so different from -O0.
3. "Hacker's Delight" by Henry S. Warren Jr. Addison-Wesley, 2nd edition — textbook
Chapter 10 covers integer division by constants — the multiply-high trick explained mathematically. Understanding where the "magic number" comes from makes reading movl $1717986919, %edx; imull %edx less mysterious and more principled.
4. GCC Internal Documentation — "RTL IR and Optimization Passes" https://gcc.gnu.org/onlinedocs/gccint
Documents GCC's optimization passes: gimplification, tree-SSA optimizations, RTL generation, register allocation, and code emission. Reading about the -O2 optimization passes explains why specific transformations (strength reduction, CMOV generation, loop invariant code motion) appear in the output.
5. "Understanding GCC Optimization" — Mark Mitchell, Alex Samuel, Geoffrey Waigh GCC documentation set
The "Optimize Options" section of GCC's manual (man gcc or gcc --help=optimizers) lists every -f flag and what it enables. Understanding which flags are included in -O2 vs. -O3 demystifies why the output looks different.
6. "Writing Optimizing Compilers" — Course Notes MIT 6.035 or similar compiler courses — OCW.MIT.edu
Graduate compiler course notes covering intermediate representations, SSA form, register allocation (graph coloring), instruction selection, and peephole optimization. Reading these makes the patterns in GCC's output predictable rather than mysterious.
7. Agner Fog's Optimization Manuals https://agner.org/optimize
"Optimizing Assembly" and "Optimizing C++" by Agner Fog are the definitive guides to understanding instruction throughput and latency on Intel/AMD CPUs. When you see GCC choose CMOV over a conditional jump, or use LEA for addition, Agner Fog's instruction tables explain the performance motivation.
8. "LLVM's TableGen and Backend Architecture" https://llvm.org/docs/TableGen
Clang/LLVM's code generation uses TableGen to describe instruction selection patterns. Understanding how Clang selects instructions from the IR helps explain why Clang and GCC produce different assembly for the same input — they have different backend implementations.
9. "Godbolt: A 10-Minute Primer" — CppCon Video Matt Godbolt, CppCon 2017 — YouTube
Matt Godbolt's own presentation on using Compiler Explorer. He shows live examples of reading compiler output, understanding optimization differences, and using the tool to debug performance issues. 45 minutes well spent.
10. "GCC Jump Tables and Branch Prediction" Multiple sources — search "GCC switch jump table" on Stack Overflow and CS.SE
Stack Overflow has excellent discussions of when GCC uses jump tables vs. if-else chains vs. binary search for switch statements. The threshold (number of cases, density of case values, likely branch probabilities) is documented in GCC's source and explained in these threads.