[llvm-commits] [llvm] r60688 - /llvm/trunk/include/llvm/Target/TargetData.h

Chris Lattner sabre at nondot.org
Sun Dec 7 22:50:51 PST 2008


Author: lattner
Date: Mon Dec  8 00:50:51 2008
New Revision: 60688

URL: http://llvm.org/viewvc/llvm-project?rev=60688&view=rev
Log:
Speed up getABITypeSize by turning a i64 mul and div into an
AND.  This is speedup on any reasonable target, but particularly
on 32-bit targets where this often turns into a libcall like udivdi3.

We know that alignments are a power of two but the compiler doesn't.

Modified:
    llvm/trunk/include/llvm/Target/TargetData.h

Modified: llvm/trunk/include/llvm/Target/TargetData.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetData.h?rev=60688&r1=60687&r2=60688&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetData.h (original)
+++ llvm/trunk/include/llvm/Target/TargetData.h Mon Dec  8 00:50:51 2008
@@ -178,8 +178,12 @@
   /// that alloca reserves for this type.  For example, returns 12 or 16 for
   /// x86_fp80, depending on alignment.
   uint64_t getABITypeSize(const Type* Ty) const {
-    unsigned char Align = getABITypeAlignment(Ty);
-    return (getTypeStoreSize(Ty) + Align - 1)/Align*Align;
+    // The alignment of a type is always a power of two.
+    unsigned char AlignMinusOne = getABITypeAlignment(Ty)-1;
+
+    // Round up to the next alignment boundary.
+    uint64_t RoundUp = getTypeStoreSize(Ty) + AlignMinusOne;
+    return RoundUp &= ~uint64_t(AlignMinusOne);
   }
 
   /// getABITypeSizeInBits - Return the offset in bits between successive





More information about the llvm-commits mailing list