Skip to content

Conversation

kazutakahirata
Copy link
Contributor

Without this patch, NumTagBits and MinTag use a recursive template Min
to compute Min.

This patch replaces Min with variadic std::min.

While I'm at it, this patch changes the type of NumTagBits to static
constexpr int.

Without this patch, NumTagBits and MinTag use a recursive template Min
to compute Min.

This patch replaces Min with variadic std::min.

While I'm at it, this patch changes the type of NumTagBits to static
constexpr int.
@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

Without this patch, NumTagBits and MinTag use a recursive template Min
to compute Min.

This patch replaces Min with variadic std::min.

While I'm at it, this patch changes the type of NumTagBits to static
constexpr int.


Full diff: https://github.com/llvm/llvm-project/pull/157390.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/PointerSumType.h (+6-11)
diff --git a/llvm/include/llvm/ADT/PointerSumType.h b/llvm/include/llvm/ADT/PointerSumType.h
index 57f045035a784..132eab58b112a 100644
--- a/llvm/include/llvm/ADT/PointerSumType.h
+++ b/llvm/include/llvm/ADT/PointerSumType.h
@@ -9,9 +9,10 @@
 #ifndef LLVM_ADT_POINTERSUMTYPE_H
 #define LLVM_ADT_POINTERSUMTYPE_H
 
-#include "llvm/ADT/bit.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/bit.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
+#include <algorithm>
 #include <cassert>
 #include <cstdint>
 #include <type_traits>
@@ -226,19 +227,13 @@ struct PointerSumTypeHelper : MemberTs... {
   };
 
   // Next we need to compute the number of bits available for the discriminant
-  // by taking the min of the bits available for each member. Much of this
-  // would be amazingly easier with good constexpr support.
-  template <uintptr_t V, uintptr_t... Vs>
-  struct Min : std::integral_constant<
-                   uintptr_t, (V < Min<Vs...>::value ? V : Min<Vs...>::value)> {
-  };
-  template <uintptr_t V>
-  struct Min<V> : std::integral_constant<uintptr_t, V> {};
-  enum { NumTagBits = Min<MemberTs::TraitsT::NumLowBitsAvailable...>::value };
+  // by taking the min of the bits available for each member.
+  static constexpr int NumTagBits =
+      std::min({MemberTs::TraitsT::NumLowBitsAvailable...});
 
   // Also compute the smallest discriminant and various masks for convenience.
   constexpr static TagT MinTag =
-      static_cast<TagT>(Min<MemberTs::Tag...>::value);
+      static_cast<TagT>(std::min({static_cast<TagT>(MemberTs::Tag)...}));
   enum : uint64_t {
     PointerMask = static_cast<uint64_t>(-1) << NumTagBits,
     TagMask = ~PointerMask

@kazutakahirata kazutakahirata merged commit fc726fb into llvm:main Sep 8, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250907_ADT_PointerSumType branch September 8, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants