When C++ Zero-Cost Abstraction fails: how-to Fix Your Compiler
summary
A C++ zero-cost abstraction stops LLVM from vectorizing a trivial element-wise add, causing Python-generated code to run about 45 μs vs 110 μs (C vs Python wrapper). The investigation uses clang’s -Rpass diagnostics, LLVM IR/MIR inspection, and a custom MIR registration to remove a struct-of-iterator roundtrip; the root cause is an instcombine interaction that leaves a phi node with the wrong type and is fixed via instcombine pointer typing. A reduced test case and patch restore SIMD adds and the expected speedup.
AI-written summary · about
chapters (6)
- 0:00Introduction and context
- 2:15Vector instructions concepts
- 7:03LLVM IR and optimizations
- 11:06Analyzing the compiler bug
- 14:48Debugging and fixing the bug
- 20:16Conclusion and Q&A
related talks
50mC++ Costless Abstractions: the compiler view
24mTowards Understanding the Costs of Avoiding Out-of-Thin-Air Results
16mSemiring Optimizations: Dynamic Elision of Expressions with Identity and Absorbing Elements
20mVectorizing Sparse Coiteration for Two-finger Loop Structure (Extended Abstract)
17mUnlocking 15% More Performance: A Case Study in LLVM Optimization for RISC-V
51mModern techniques for keeping your code dry
54mCost of Abstractions in Embedded Systems
37mC++ Zero Overhead Pass by Value Through Invocable C++ Abstractions
