Why This Matters
This article highlights recent optimizations in LLVM's SmallVector::push_back operation, particularly for trivially-copyable types, which are critical for performance in many C++ applications. The improvements focus on reducing unnecessary register saves and stack operations, leading to faster code execution and more efficient use of resources, ultimately benefiting both compiler developers and end-users by enabling more performant software.
Key Takeaways
- Optimizations in SmallVector::push_back improve performance for trivially-copyable types.
- Efficient handling of callee-saved registers reduces unnecessary stack operations.
- Compiler techniques like shrink wrapping have limitations in optimizing certain code paths.
tl;dr This blog post describes a recent SmallVector::push_back optimization for approximately trivially copyable element types.
SmallVector is LLVM's most-used container, and push_back its hot operation. For the trivially-copyable specialization the fast path should be fast.
1
2
3
void f (llvm::SmallVectorImpl< int > &v, int x) { v. push_back (x); }
clang -S --target=x86_64 -O2 -DNDEBUG a.cc generates:
... continue reading