Hasty Briefsbeta

Bilingual

Matt Godbolt's blog

15 hours ago
  • The compiler optimizes loops by moving invariant code (like size calculations) outside the loop, known as Loop-Invariant Code Motion (LICM).
  • In a string_view counting example, clang moves the get_range() call outside the loop and uses setle/setge to avoid branches.
  • Trust the compiler, but verify its output using tools like Compiler Explorer, as gcc may fail to perform LICM on certain struct types.