From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9312C3857B9B; Mon, 25 Sep 2023 10:26:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9312C3857B9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695637590; bh=KYmMtlzGjtcOVOWijKWabouWol4a1GZUoXUXRoH0+UY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VUv501M732Jay2Tbj1fBzxQOVYjSDyDN5dD0gcjj7wUdS4Kcvs8+f4YDr71IdxdgQ p3a3rh4DwGHo+BVP2qkAySveZt1ifc43U4BTA3YNkvmsndLKoFq0eYG4bcrA8OsNfN cwaBcWia9D6KbM/rYtgSQzPI3G0OaWbRQtEYQwo0= From: "redbeard0531 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/104611] memcmp/strcmp/strncmp can be optimized when the result is tested for [in]equality with 0 on aarch64 Date: Mon, 25 Sep 2023 10:26:29 +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: redbeard0531 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: cc 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=3D104611 Mathias Stearn changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |redbeard0531 at gmail dot = com --- Comment #4 from Mathias Stearn --- clang has already been using the optimized memcmp code since v16, even at -= O1: https://www.godbolt.org/z/qEd768TKr. Older versions (at least since v9) were still branch-free, but via a less optimal sequence of instructions. GCC's code gets even more ridiculous at 32 bytes, because it does a branch after every 8-byte compare, while the clang code is fully branch-free (not = that branch-free is always better, but it seems clearly so in this case). Judging by the codegen, there seems to be three deficiencies in GCC: 1) an inability to take advantage of the load-pair instructions to load 16-bytes = at a time, and 2) an inability to use ccmp to combine comparisons. 3) using branching rather than cset to fill the output register. Ideally these could= all be done in the general case by the low level instruction optimizer, but even getting them special cased for memcmp (and friends) would be an improvement= .=