Index: libc/src/string/memory_utils/memcmp_implementations.h =================================================================== --- libc/src/string/memory_utils/memcmp_implementations.h +++ libc/src/string/memory_utils/memcmp_implementations.h @@ -22,6 +22,9 @@ namespace __llvm_libc { [[maybe_unused]] LIBC_INLINE MemcmpReturnType inline_memcmp_embedded_tiny(CPtr p1, CPtr p2, size_t count) { + if (p1 == p2) + return MemcmpReturnType::ZERO(); + LLVM_LIBC_LOOP_NOUNROLL for (size_t offset = 0; offset < count; ++offset) if (auto value = generic::Memcmp<1>::block(p1 + offset, p2 + offset)) Index: libc/src/string/memory_utils/strcmp_implementations.h =================================================================== --- libc/src/string/memory_utils/strcmp_implementations.h +++ libc/src/string/memory_utils/strcmp_implementations.h @@ -16,6 +16,9 @@ template constexpr static int strcmp_implementation(const char *left, const char *right, Comp &&comp) { + if (left == right) + return 0; + // TODO: Look at benefits for comparing words at a time. for (; *left && !comp(*left, *right); ++left, ++right) ; @@ -29,6 +32,9 @@ if (n == 0) return 0; + if (left == right) + return 0; + // TODO: Look at benefits for comparing words at a time. for (; n > 1; --n, ++left, ++right) { char lc = *left;