[llvm] [ADT] Add LLVM_UNLIKELY hint to SmallVector::reserve() (PR #178606)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 28 23:00:51 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: puneeth_aditya_5656 (mugiwaraluffy56)
<details>
<summary>Changes</summary>
## Summary
Add `LLVM_UNLIKELY` branch prediction hint to `SmallVector::reserve()` for the case where reallocation is needed.
## Rationale
- The common case for `reserve()` is that capacity is already sufficient (defensive calls, repeated reserves)
- This matches the existing pattern in `reserveForParamAndGetAddressImpl()` at line 238 which uses `LLVM_LIKELY` for the same capacity check
- Helps branch predictor optimize for the fast path
## Test plan
- [ ] Existing SmallVector unit tests pass
- [ ] LLVM builds successfully
---
Full diff: https://github.com/llvm/llvm-project/pull/178606.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/SmallVector.h (+1-1)
``````````diff
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 23d40c3e07675..dedf162187474 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -664,7 +664,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
}
void reserve(size_type N) {
- if (this->capacity() < N)
+ if (LLVM_UNLIKELY(this->capacity() < N))
this->grow(N);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/178606
More information about the llvm-commits
mailing list