[llvm] 54971c8 - [llvm] Use llvm::bit_ceil (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 29 12:14:32 PST 2023
On Sun, Jan 29, 2023, at 09:12, Kazu Hirata via llvm-commits wrote:
>
> Author: Kazu Hirata
> Date: 2023-01-29T00:12:53-08:00
> New Revision: 54971c8a39e8b682e7a042eee33f94a8283d8305
>
> URL: https://github.com/llvm/llvm-project/commit/54971c8a39e8b682e7a042eee33f94a8283d8305
> DIFF: https://github.com/llvm/llvm-project/commit/54971c8a39e8b682e7a042eee33f94a8283d8305.diff
>
> LOG: [llvm] Use llvm::bit_ceil (NFC)
>
> If X is nonzero, NextPowerOf2(X - 1) is equivalent to
> llvm::bit_ceil(X). In this patch, std::max guarantees that X is
> nonzero.
This causes a measurable compile-time regression: https://llvm-compile-time-tracker.com/compare.php?from=0de61934a37180d6028852740eaa0e9e409d001a&to=54971c8a39e8b682e7a042eee33f94a8283d8305&stat=instructions:u
The DenseMap changes should probably be reverted, as they are performance-critical.
Regards,
Nikita
>
> Added:
>
>
> Modified:
> llvm/include/llvm/ADT/DenseMap.h
> llvm/lib/Transforms/Utils/SimplifyCFG.cpp
>
> Removed:
>
>
>
> ################################################################################
> diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
> index 7adc6710cfa8..9a6852646268 100644
> --- a/llvm/include/llvm/ADT/DenseMap.h
> +++ b/llvm/include/llvm/ADT/DenseMap.h
> @@ -803,7 +803,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
> unsigned OldNumBuckets = NumBuckets;
> BucketT *OldBuckets = Buckets;
>
> - allocateBuckets(std::max<unsigned>(64, static_cast<unsigned>(NextPowerOf2(AtLeast-1))));
> + allocateBuckets(llvm::bit_ceil(std::max(64u, AtLeast)));
> assert(Buckets);
> if (!OldBuckets) {
> this->BaseT::initEmpty();
> @@ -1042,7 +1042,7 @@ class SmallDenseMap
>
> void grow(unsigned AtLeast) {
> if (AtLeast > InlineBuckets)
> - AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast-1));
> + AtLeast = llvm::bit_ceil(std::max(64u, AtLeast));
>
> if (Small) {
> // First move the inline buckets into a temporary storage.
>
> diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
> index 372a6698ce8a..e6d9b265dab9 100644
> --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
> +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
> @@ -6552,7 +6552,7 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
>
> // Make the mask's bitwidth at least 8-bit and a power-of-2 to avoid
> // unnecessary illegal types.
> - uint64_t TableSizePowOf2 = NextPowerOf2(std::max(7ULL, TableSize - 1ULL));
> + uint64_t TableSizePowOf2 = llvm::bit_ceil(std::max<uint64_t>(8, TableSize));
> APInt MaskInt(TableSizePowOf2, 0);
> APInt One(TableSizePowOf2, 1);
> // Build bitmask; fill in a 1 bit for every case.
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230129/b3a5712a/attachment.html>
More information about the llvm-commits
mailing list