Get Started

Compiler Idioms: What Optimization Does to Your Code and How to Read It Back

An optimizing compiler replaces source constructs with cheaper instruction shapes. Each shape has a derivation, and this lesson builds the recognizer that runs the derivation backwards and checks it against the source.

150 minutesBuildPython, C, x86-64 assembly, AArch64 assemblyMembers

Learning Objectives

  • Derive the magic number and shift for division by any constant with the Granlund-Montgomery bound, and recover the divisor from the constants clang emitted.
  • Name the five ways LLVM lowers a switch and read the entry count, the table location, and the entries from the object.
  • Read a vectorized loop as lanes, accumulators, elements per iteration, trip-count mask, reduction, and remainder loop.
  • Recognize tail calls, inlined callees, branchless selects, and loops that became memset or memcpy.
  • Report every idiom with its evidence instructions and its decoded source form, on x86-64 and on AArch64, at -O0 through -O3.
  • Compare the result with what Ghidra, angr, radare2, rizin, and lldb show for the same bytes.