Matt Godbolt's blog
15 hours ago
- GCC optimizes a simple sum loop by processing two numbers at a time using LEA instructions, achieving O(n) but with fewer iterations.
- Clang goes further by recognizing the sum of integers formula and replacing the loop with an O(1) closed-form expression: v(v-1)/2.
- The author notes decades of compiler development still produce surprising and elegant optimizations, highlighting the sophistication of modern compilers.