From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E9DF53858C33; Tue, 10 Oct 2023 07:37:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9DF53858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696923437; bh=lmBd+qxVqYmBPzCO7cPFnnI8xlc4yTdE1/PA8whDr0E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MBFuxbFq6Eu5JFJLz7gCve4GlSA/uWsj5ZACEiTNaIymIMRWL9TLPNdSSH2TbZJMr EDyPNCkhhWWrFwqDodqZoUrfySHmeWDWlwJ+rFBYM5autEGlkLQTDA+SRhsIZCPcLI MKE55Y351djwwkDpxvsYaPKMpQ++afmh3Cog8hpM= From: "crazylht at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/104610] memcmp () == 0 can be optimized better for avx512f Date: Tue, 10 Oct 2023 07:37:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: crazylht at gmail dot com X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104610 --- Comment #22 from Hongtao.liu --- For 64-byte memory comparison int compare (const char* s1, const char* s2) { return __builtin_memcmp (s1, s2, 64) =3D=3D 0; } We're generating vmovdqu (%rsi), %ymm0 vpxorq (%rdi), %ymm0, %ymm0 vptest %ymm0, %ymm0 jne .L2 vmovdqu 32(%rsi), %ymm0 vpxorq 32(%rdi), %ymm0, %ymm0 vptest %ymm0, %ymm0 je .L5 .L2: movl $1, %eax xorl $1, %eax vzeroupper ret An alternative way is using vpcmpeq + kortest and check Carry bit vmovdqu64 (%rsi), %zmm0 xorl %eax, %eax vpcmpeqd (%rdi), %zmm0, %k0 kortestw %k0, %k0 setc %al vzeroupper Not sure if it's better or not.=