Always-inline HashSelect::HashValueProbe::Invoke() and bool AbslHashValue.
Annotate AbslHashValue for bool and HashSelect::HashValueProbe::Invoke() in hash.h with ABSL_ATTRIBUTE_ALWAYS_INLINE.
Flattening HashValueProbe::Invoke() together with the bool AbslHashValue overload (`value ? ~size_t{} : 0`) during AlwaysInlinerPass removes intermediate HashValueProbe dispatch frames around custom and built-in AbslHashValue implementations and lets InstCombinePass fold the negated bool mask directly into the CRC32 fast path's `3 * v` lane as `-(3 * b)` instead of materializing `3 * (b ^ 1) - 3` via `xorb $0x1`, movzbl, leaq, and `addq $-0x3`, cutting each hashed bool on x86-64 from 9 instructions (10 uOps) to 6 instructions (7 uOps).
PiperOrigin-RevId: 1014901982
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
index 8303ff9..b631c71 100644
--- a/absl/hash/internal/hash.h
+++ b/absl/hash/internal/hash.h
@@ -450,8 +450,8 @@
// We use SFINAE to ensure that this overload only accepts bool, not types that
// are convertible to bool.
template <typename H, typename B>
-std::enable_if_t<std::is_same_v<B, bool>, H> AbslHashValue(H hash_state,
- B value) {
+ABSL_ATTRIBUTE_ALWAYS_INLINE inline std::enable_if_t<std::is_same_v<B, bool>, H>
+AbslHashValue(H hash_state, B value) {
// We use ~size_t{} instead of 1 so that all bits are different between
// true/false instead of only 1.
return H::combine(std::move(hash_state),
@@ -1397,9 +1397,10 @@
// The std::conditional_t<false, H, T> test is to enable SFINAE by making T
// be a dependent type.
template <typename H>
- static H Invoke(H state, type_traits_internal::AddConstRefIfExpensiveToCopy<
- std::conditional_t<false, H, T>>
- value) {
+ ABSL_ATTRIBUTE_ALWAYS_INLINE static H Invoke(
+ H state, type_traits_internal::AddConstRefIfExpensiveToCopy<
+ std::conditional_t<false, H, T>>
+ value) {
return AbslHashValue(std::move(state), value);
}
};