From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 00776385514C for ; Mon, 12 Dec 2022 13:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00776385514C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670853406; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=yNyymg+L0KrI91O0SpQ39mMm72hiRiNKzyBeBqZZiT8=; b=D1Atv9Hd21/E71hs6k24uNcwx/uUGs4PQFIPBSRAb+7RYvLNYfhRRbBCkyOEb0Gogo6unO 6gngWdfle+mWxd1/OebQ9tFuWzQu3t71MXXDJnh5ZWBB92u/PNgATyqOVGZg4txJZJUwXf VqrXTgbI1oeNJaKm65j734+mfVAw2QY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-252-3OCfSNyiPJWrjEJ0RE3FxA-1; Mon, 12 Dec 2022 08:56:43 -0500 X-MC-Unique: 3OCfSNyiPJWrjEJ0RE3FxA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C2CC855438; Mon, 12 Dec 2022 13:56:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED7A779A1; Mon, 12 Dec 2022 13:56:42 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BCDubBV4130458 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 12 Dec 2022 14:56:38 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BCDuaiG4130457; Mon, 12 Dec 2022 14:56:36 +0100 Date: Mon, 12 Dec 2022 14:56:36 +0100 From: Jakub Jelinek To: Alejandro Colomar Cc: Martin =?utf-8?B?TGnFoWth?= , gcc@gcc.gnu.org, GNU C Library Subject: Re: Missing optimization: mempcpy(3) vs memcpy(3) Message-ID: Reply-To: Jakub Jelinek References: <8f9d61cf-14a5-4099-e2b6-7c8cac47a28b@suse.cz> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Dec 12, 2022 at 02:44:04PM +0100, Alejandro Colomar via Gcc wrote: > > I don't see any problem with the code snippets you provided. > > Well, then the optimization may be the other way around (although I question > why it is implemented that way, and not the other way around, but I'm not a > hardware or libc guy, so there may be reasons). > > If calling memcpy(3) is better, then the code calling mempcpy(3) could be > expanded inline to call it (but I doubt it). > > If calling mempcpy(3) is better, then the hand-made pattern resembling > mempcpy(3) should probably be merged as a call to mempcpy(3). > > But acting different on equivalent calls to both of them seems inconsistent > to me, unless you trust the programmer to know better how to optimize, that > is... I think that is the case, plus the question if one can use a non-standard function to implement a standard function (and if it would be triggered by seeing an expected prototype for the non-standard function). Otherwise, whether mempcpy in libc is implemented as memcpy + tweak return value or has its own implementation is something that is heavily dependent on the target and changes over time, so hardcoding that in gcc is problematic. For -Os mempcpy call might be very well smaller even if the library side is then slower. Jakub