[llvm] c6008ce - [DL] Invert `getTypeStoreSize` bytes/bits relationship to avoid ceil div (NFC)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 31 00:08:45 PDT 2024


Author: Antonio Frighetto
Date: 2024-08-31T09:04:05+02:00
New Revision: c6008cef7a710b3d97e6b9b6fcf8e9661333c5e6

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

LOG: [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.

Added: 
    

Modified: 
    llvm/include/llvm/IR/DataLayout.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h
index 145f1a29c7dfb7..8f7ab2f9df389e 100644
--- a/llvm/include/llvm/IR/DataLayout.h
+++ b/llvm/include/llvm/IR/DataLayout.h
@@ -421,8 +421,9 @@ class DataLayout {
   ///
   /// For example, returns 5 for i36 and 10 for x86_fp80.
   TypeSize getTypeStoreSize(Type *Ty) const {
-    TypeSize BaseSize = getTypeSizeInBits(Ty);
-    return {divideCeil(BaseSize.getKnownMinValue(), 8), BaseSize.isScalable()};
+    TypeSize StoreSizeInBits = getTypeStoreSizeInBits(Ty);
+    return {StoreSizeInBits.getKnownMinValue() / 8,
+            StoreSizeInBits.isScalable()};
   }
 
   /// Returns the maximum number of bits that may be overwritten by
@@ -433,7 +434,10 @@ class DataLayout {
   ///
   /// For example, returns 40 for i36 and 80 for x86_fp80.
   TypeSize getTypeStoreSizeInBits(Type *Ty) const {
-    return 8 * getTypeStoreSize(Ty);
+    TypeSize BaseSize = getTypeSizeInBits(Ty);
+    uint64_t AlignedSizeInBits =
+        alignToPowerOf2(BaseSize.getKnownMinValue(), 8);
+    return {AlignedSizeInBits, BaseSize.isScalable()};
   }
 
   /// Returns true if no extra padding bits are needed when storing the


        


More information about the llvm-commits mailing list