Skip to content

Commit 698d832

Browse files
authored
DataLayout: Fix latent issues with getMaxIndexSizeInBits (#118740)
Because it was implemented in terms of getMaxIndexSize, it was always rounding the values up to a multiple of 8. Additionally, it was using the PointerSpec's BitWidth rather than its IndexBitWidth, which was self-evidently incorrect. Since getMaxIndexSize was only used by getMaxIndexSizeInBits, and its name and function seem niche and somewhat confusing, go ahead and remove it until a concrete need for it arises.
1 parent 1d3f9f8 commit 698d832

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,6 @@ class DataLayout {
330330
/// the backends/clients are updated.
331331
unsigned getPointerSize(unsigned AS = 0) const;
332332

333-
/// Returns the maximum index size over all address spaces.
334-
unsigned getMaxIndexSize() const;
335-
336333
// Index size in bytes used for address calculation,
337334
/// rounded up to a whole number of bytes.
338335
unsigned getIndexSize(unsigned AS) const;
@@ -369,9 +366,7 @@ class DataLayout {
369366
}
370367

371368
/// Returns the maximum index size over all address spaces.
372-
unsigned getMaxIndexSizeInBits() const {
373-
return getMaxIndexSize() * 8;
374-
}
369+
unsigned getMaxIndexSizeInBits() const;
375370

376371
/// Size in bits of index used for address calculation in getelementptr.
377372
unsigned getIndexSizeInBits(unsigned AS) const {

llvm/lib/IR/DataLayout.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,12 +740,10 @@ unsigned DataLayout::getPointerSize(unsigned AS) const {
740740
return divideCeil(getPointerSpec(AS).BitWidth, 8);
741741
}
742742

743-
unsigned DataLayout::getMaxIndexSize() const {
743+
unsigned DataLayout::getMaxIndexSizeInBits() const {
744744
unsigned MaxIndexSize = 0;
745745
for (const PointerSpec &Spec : PointerSpecs)
746-
MaxIndexSize =
747-
std::max(MaxIndexSize, (unsigned)divideCeil(Spec.BitWidth, 8));
748-
746+
MaxIndexSize = std::max(MaxIndexSize, Spec.IndexBitWidth);
749747
return MaxIndexSize;
750748
}
751749

0 commit comments

Comments
 (0)