Skip to content

Commit c6008ce

Browse files
[DL] Invert getTypeStoreSize bytes/bits relationship to avoid ceil div (NFC)
Change how `getTypeStoreSize` and `getTypeStoreSizeInBits` interact by first aligning the bit size to the nearest power of 2 boundary and then applying plain division to derive the byte size. This simplifies the calculation by avoiding possible overflow concerns in the first place.
1 parent e4cf0a0 commit c6008ce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ class DataLayout {
421421
///
422422
/// For example, returns 5 for i36 and 10 for x86_fp80.
423423
TypeSize getTypeStoreSize(Type *Ty) const {
424-
TypeSize BaseSize = getTypeSizeInBits(Ty);
425-
return {divideCeil(BaseSize.getKnownMinValue(), 8), BaseSize.isScalable()};
424+
TypeSize StoreSizeInBits = getTypeStoreSizeInBits(Ty);
425+
return {StoreSizeInBits.getKnownMinValue() / 8,
426+
StoreSizeInBits.isScalable()};
426427
}
427428

428429
/// Returns the maximum number of bits that may be overwritten by
@@ -433,7 +434,10 @@ class DataLayout {
433434
///
434435
/// For example, returns 40 for i36 and 80 for x86_fp80.
435436
TypeSize getTypeStoreSizeInBits(Type *Ty) const {
436-
return 8 * getTypeStoreSize(Ty);
437+
TypeSize BaseSize = getTypeSizeInBits(Ty);
438+
uint64_t AlignedSizeInBits =
439+
alignToPowerOf2(BaseSize.getKnownMinValue(), 8);
440+
return {AlignedSizeInBits, BaseSize.isScalable()};
437441
}
438442

439443
/// Returns true if no extra padding bits are needed when storing the

0 commit comments

Comments
 (0)