Article URL: https://tiki.li/blog/lucky_code.html Comments URL: https://news.ycombinator.com/item?id=48870799 Points: 78 # Comments: 29

Recently, while I was working on an optimized Quicksort implementation, I came across a rather interesting quirk. Modern compilers (especially Clang) optimize loops using fast, branch-free instructions - provided you use the right programming style. It is already micro-optimized using sorting networks and loop unrolling. Only a few cosmetic changes remain. We rewrite this beginner‑friendly style, which explicitly shows how the pointers are moved: GCC does not exhibit this “quirk” (different code generation for logically equivalent source). It consistently generates the slower branch-based version.