From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CAFE83858D32; Wed, 15 Jun 2022 18:01:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAFE83858D32 From: "pdimov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/105992] New: memcmp(p, q, 7) == 0 can be optimized better on x86 Date: Wed, 15 Jun 2022 18:01:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pdimov at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2022 18:01:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105992 Bug ID: 105992 Summary: memcmp(p, q, 7) =3D=3D 0 can be optimized better on x86 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: pdimov at gmail dot com Target Milestone: --- bool eq( char const* p ) { return __builtin_memcmp( p, "literal", 7 ) =3D=3D 0; } generates eq(char const*): cmp DWORD PTR [rdi], 1702127980 je .L6 .L2: mov eax, 1 test eax, eax sete al ret .L6: xor eax, eax cmp DWORD PTR [rdi+3], 1818325605 jne .L2 test eax, eax sete al ret (https://godbolt.org/z/68MKqGz9T) but LLVM does eq(char const*): # @eq(char const*) mov eax, 1702127980 xor eax, dword ptr [rdi] mov ecx, 1818325605 xor ecx, dword ptr [rdi + 3] or ecx, eax sete al ret (https://godbolt.org/z/jxcb85Ysa) There are similar bugs for ARM (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104611) and AVX512 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104610) but I haven't found= one for vanilla x86. Recent changes to std::string::operator=3D=3D make it use the above pattern: https://godbolt.org/z/8KxqqG9cx=