diff --git a/libc/src/string/memory_utils/bcmp_implementations.h b/libc/src/string/memory_utils/bcmp_implementations.h --- a/libc/src/string/memory_utils/bcmp_implementations.h +++ b/libc/src/string/memory_utils/bcmp_implementations.h @@ -143,7 +143,7 @@ [[maybe_unused]] LIBC_INLINE BcmpReturnType inline_bcmp_x86(CPtr p1, CPtr p2, size_t count) { - if (count == 0) + if (count == 0 || p1 == p2) return BcmpReturnType::ZERO(); if (count == 1) return generic::Bcmp<1>::block(p1, p2); diff --git a/libc/src/string/memory_utils/x86_64/memcmp_implementations.h b/libc/src/string/memory_utils/x86_64/memcmp_implementations.h --- a/libc/src/string/memory_utils/x86_64/memcmp_implementations.h +++ b/libc/src/string/memory_utils/x86_64/memcmp_implementations.h @@ -70,7 +70,7 @@ LIBC_INLINE MemcmpReturnType inline_memcmp_x86(CPtr p1, CPtr p2, size_t count) { - if (count == 0) + if (count == 0 || p1 == p2) return MemcmpReturnType::ZERO(); if (count == 1) return generic::Memcmp<1>::block(p1, p2);