[llvm] [ADT] Always use 32-bit size type for SmallVector with 16-bit elements (PR #95536)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 06:04:33 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Jay Foad (jayfoad)

<details>
<summary>Changes</summary>

SmallVector has a special case to allow vector of char to exceed 4 GB in
size on 64-bit hosts. Apply this special case only for 8-bit element
types, instead of all element types < 32 bits.

This makes SmallVector<MCPhysReg> more compact because MCPhysReg is
uint16_t.


---
Full diff: https://github.com/llvm/llvm-project/pull/95536.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/SmallVector.h (+1-2) 


``````````diff
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 09676d792dfeb..d7e889cc7b1e4 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -116,8 +116,7 @@ template <class Size_T> class SmallVectorBase {
 
 template <class T>
 using SmallVectorSizeType =
-    std::conditional_t<sizeof(T) < 4 && sizeof(void *) >= 8, uint64_t,
-                       uint32_t>;
+    std::conditional_t<sizeof(T) == 1, uintptr_t, uint32_t>;
 
 /// Figure out the offset of the first element.
 template <class T, typename = void> struct SmallVectorAlignmentAndSize {

``````````

</details>


https://github.com/llvm/llvm-project/pull/95536


More information about the llvm-commits mailing list