From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A59F43858C5F; Wed, 22 Nov 2023 07:33:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A59F43858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700638405; bh=2dzhBCeCM5K+lLbyYr10V9s3Ne2MfSvgfbPKE3juHMo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JlmC46vPX7XbaYmk59xVb2pk12dRZaoNeel68zo8j/QHUkZV/FnGD+7Cywx6irdMQ fyK8oXxl454DnzuJH4RticgR5FsM80wBqYl0IuDlvfwocbUCo6yY4rTAKRkW1nUG/g oVHBxKAtPKuZty1UJTCOzsYj7bxRkqOYZrJUKX60= From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/32667] block copy with exact overlap is expanded as memcpy Date: Wed, 22 Nov 2023 07:33:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de 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=3D32667 --- Comment #25 from rguenther at suse dot de --- On Tue, 21 Nov 2023, bugdal at aerifal dot cx wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D32667 >=20 > Rich Felker changed: >=20 > What |Removed |Added > -------------------------------------------------------------------------= --- > CC| |bugdal at aerifal dot cx >=20 > --- Comment #24 from Rich Felker --- > If the copy is such that gcc is happy to emit an external call to memcpy = for > it, there is no significant size or performance cost to emitting a branch > checking for equality before making the call, and performing this branch = would > greatly optimize the (maybe rare in the caller, maybe not) case of > self-assignment! >=20 > On the other hand, expecting the libc memcpy to make this check greatly > pessimizes every reasonable small use of memcpy with a gratuitous branch = for > what is undefined behavior and should never appear in any valid program. >=20 > Fix it on the compiler side please. The only reasonable fix on the compiler side is to never emit memcpy but always use memmove. The pessimization of that compared to the non-existing "real" issue with calling memcpy with exact overlap is the reason for the non-action.=