From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 12B2E3891C35; Mon, 21 Jun 2021 07:56:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12B2E3891C35 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/11877] gcc should use xor trick with -Os Date: Mon, 21 Jun 2021 07:56:39 +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: 3.3.1 X-Bugzilla-Keywords: patch X-Bugzilla-Severity: enhancement X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: kazu 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 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: Mon, 21 Jun 2021 07:56:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D11877 --- Comment #10 from CVS Commits --- The master branch has been updated by Roger Sayle : https://gcc.gnu.org/g:9cedbaab8e048b90ceb9ceef0d851385fae67cde commit r12-1668-g9cedbaab8e048b90ceb9ceef0d851385fae67cde Author: Roger Sayle Date: Mon Jun 21 08:54:50 2021 +0100 PR target/11877: Use xor to write zero to memory with -Os The following patch attempts to resolve PR target/11877 (without triggering PR/23102). On x86_64, writing an SImode or DImode zero to memory uses an instruction encoding that is larger than first clearing a register (using xor) then writing that to memory. Hence, after reload, the peephole2 pass can determine if there's a suitable free register, and if so, use that to shrink the code size with -Os. To improve code size, and avoid inserting a large number of xor instructions (PR target/23102), this patch makes use of peephole2's efficient pattern matching to use a single temporary for a run of consecutive writes. In theory, one could do better still with a new target-specific pass, gated on -Os, to shrink these instructions (like stv), but that's probably overkill for the little remaining space savings. Evaluating this patch on the CSiBE benchmark (v2.1.1) results in a 0.26% code size improvement (3715273 bytes down to 3705477) on x86_64 with -Os [saving 1 byte every 400]. 549 of 894 tests improve, two tests grow larger. Analysis of these 2 pathological cases reveals that although peephole2's match_scratch prefers to use a call-clobbered register (to avoid requiring a new stack frame), very rarely this interacts with GCC's shrink wrapping optimization, which may previously have avoided saving/restoring a call clobbered register, such as %eax, in the calling function. 2021-06-21 Roger Sayle gcc/ChangeLog PR target/11877 * config/i386/i386.md: New define_peephole2s to shrink writing 1, 2 or 4 consecutive zeros to memory when optimizing for size. gcc/testsuite/ChangeLog PR target/11877 * gcc.target/i386/pr11877.c: New test case.=