diff options
author | Chris Lattner <sabre@nondot.org> | 2008-12-08 06:50:51 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-12-08 06:50:51 +0000 |
commit | 0a3ba71a0576fbde5b8ce1ff276f63f3f3d16229 (patch) | |
tree | 8d4e141adf5312daa138c60f561a00ad0bdf8e93 | |
parent | 295d4e953a1214f60632220b9fcb31c1af8b0c27 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60688 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Target/TargetData.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h index 7c274cec2d..fdb21c5ea1 100644 --- a/include/llvm/Target/TargetData.h +++ b/include/llvm/Target/TargetData.h @@ -178,8 +178,12 @@ public: /// 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 |