[llvm] 38b376f - [DataLayout] Use linear scan to determine integer alignment (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 05:05:02 PDT 2025


Author: Nikita Popov
Date: 2025-09-03T14:04:54+02:00
New Revision: 38b376f1927df5c1dea1065041779b28b13b9dd9

URL: https://github.com/llvm/llvm-project/commit/38b376f1927df5c1dea1065041779b28b13b9dd9
DIFF: https://github.com/llvm/llvm-project/commit/38b376f1927df5c1dea1065041779b28b13b9dd9.diff

LOG: [DataLayout] Use linear scan to determine integer alignment (NFC)

The number of alignment entries is usually very small (5-7), so
it is more efficient to use a linear scan than a binary search.

Added: 
    

Modified: 
    llvm/lib/IR/DataLayout.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index 50c45f5f5feb0..ee43ad49d0df2 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -694,7 +694,12 @@ void DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth,
 
 Align DataLayout::getIntegerAlignment(uint32_t BitWidth,
                                       bool abi_or_pref) const {
-  auto I = lower_bound(IntSpecs, BitWidth, LessPrimitiveBitWidth());
+  auto I = IntSpecs.begin();
+  for (; I != IntSpecs.end(); ++I) {
+    if (I->BitWidth >= BitWidth)
+      break;
+  }
+
   // If we don't have an exact match, use alignment of next larger integer
   // type. If there is none, use alignment of largest integer type by going
   // back one element.


        


More information about the llvm-commits mailing list