From patchwork Sat Mar 9 08:34:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1909931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N6Wek58G; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TsGZn44gPz1yWy for ; Sat, 9 Mar 2024 19:35:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33CC83851C02 for ; Sat, 9 Mar 2024 08:35:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4B74C385E457 for ; Sat, 9 Mar 2024 08:35:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B74C385E457 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4B74C385E457 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709973316; cv=none; b=IW8RLIh4ro5a3w2cza52ViFG+PKHuy+kN7FueCfYpub67VXyD2Nw2BG31Blk/vP6js62irEP1vaqRfVs0cL8ZDT12yBhDY9bRLCj9+z20xO3f0esrMAVpb8OUWP1Af780YWo6PCSq5qlIxfudvQOw5bbOv6FEw4E6g389N+nMsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709973316; c=relaxed/simple; bh=K6c2+4mnhM5Bw2FJ43Wjn2Qz851RkbUEwwpw6HPbFN8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Sg4O1l/HgjNYLX/8Uv7pqRkVxbhEs8t9Xp4NB+u87G/E03abZzblI4WzZr1kWCjurlPTtL8jqEjSQfycXtvsGnKSYciY8ghTJRCjQdMf4UDYZOBiXMSMmyK8TlhWSazZ4CzBdbTmbPgZJrI0N/GE+8IJdv2oskuYaepqi0yrJHA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709973308; 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; bh=OlTw7CCwKd+XsYA+7SQI9YN7y+VValK+B8KhG18lUKk=; b=N6Wek58GHzKiGpg0J/5YUbyd+5zwYPvEkDMfHfju3JYGATImGRDEP7g2VOrVfTaF1Zq1JY 0dUkM3RiMw6KDy4M1s0ayl1KK9x4OZdfqlMC3mJHk33M5JL1o37hy4On03uewOuVrGePox tkSYMYwMul9voMtgqwnNBFqSqIkNJjs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-532-fb6gY_Y-MSexRcjCXPvCQg-1; Sat, 09 Mar 2024 03:35:03 -0500 X-MC-Unique: fb6gY_Y-MSexRcjCXPvCQg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4696D3C02467; Sat, 9 Mar 2024 08:35:03 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.226.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF84837F6; Sat, 9 Mar 2024 08:35:02 +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 4298YnLm1519770 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 9 Mar 2024 09:34:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4298YhEQ1519769; Sat, 9 Mar 2024 09:34:43 +0100 Date: Sat, 9 Mar 2024 09:34:43 +0100 From: Jakub Jelinek To: Jeff Law , Richard Biener , Eric Botcazou Cc: gcc-patches@gcc.gnu.org, Roger Sayle Subject: [PATCH] fwprop: Restore previous behavior for forward propagation of RTL with MEMs [PR114284] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! Before the recent PR111267 r14-8319 fwprop changes, fwprop would never try to propagate what was not considered PROFITABLE, where the profitable part actually was partly about profitability, partly about very good reasons not to actually propagate and partly for cases where propagation is completely incorrect. In particular, classify_result has: /* Allow (subreg (mem)) -> (mem) simplifications with the following exceptions: 1) Propagating (mem)s into multiple uses is not profitable. 2) Propagating (mem)s across EBBs may not be profitable if the source EBB runs less frequently. 3) Propagating (mem)s into paradoxical (subreg)s is not profitable. 4) Creating new (mem/v)s is not correct, since DCE will not remove the old ones. */ if (single_use_p && single_ebb_p && SUBREG_P (old_rtx) && !paradoxical_subreg_p (old_rtx) && MEM_P (new_rtx) && !MEM_VOLATILE_P (new_rtx)) return PROFITABLE; and didn't mark any other MEM_P (new_rtx) or rtxes which contain a MEM in its subrtxes as PROFITABLE. Now, since r14-8319 profitable_p method has been renamed to likely_profitable_p and has just a minor role. Now, rule 4) above is something that isn't about profitability, but about correct behavior, if you propagate mem/v, the code is miscompiled. This particular case has been fixed elsewhere by Haochen in r14-9379. But I think even the 1) and 2) and maybe 3) are a strong don't do it, don't rely solely on rtx costs, increasing the number of loads of the same memory, even when cached, is undesirable, canceling load hoisting can be undesirable as well. So, the following patch restores previous behavior of src contains any MEMs, in that case likely_profitable_p () is taken as the old profitable_p () as a requirement rather than just a hint. For propagation of something which doesn't load from memory this keeps the r14-8319 behavior. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-09 Jakub Jelinek PR target/114284 * fwprop.cc (try_fwprop_subst_pattern): Don't propagate src containing MEMs unless prop.likely_profitable_p (). Jakub --- gcc/fwprop.cc.jj 2024-03-08 09:07:29.371626376 +0100 +++ gcc/fwprop.cc 2024-03-08 16:18:16.125853619 +0100 @@ -451,6 +451,7 @@ try_fwprop_subst_pattern (obstack_waterm if (!prop.likely_profitable_p () && (prop.changed_mem_p () + || contains_mem_rtx_p (src) || use_insn->is_asm () || !single_set (use_rtl))) {