From patchwork Tue Nov 28 17:30:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 170879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp4095700vqx; Tue, 28 Nov 2023 09:31:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCzNymR4ZaTYeGRtDPs11/K6n4xQ4us4doDt4qMER7zHlppkwRNDnyrWAHHp3cWBsWZSVz X-Received: by 2002:a05:620a:888a:b0:77d:7cfd:e46a with SMTP id qk10-20020a05620a888a00b0077d7cfde46amr21771331qkn.15.1701192690989; Tue, 28 Nov 2023 09:31:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701192690; cv=pass; d=google.com; s=arc-20160816; b=qdcJhntncHvsYT15UBSIflyHfIfzfpno6nU6xl6139RXvXvgtbNvAphmLiP/p4Cbbo Ud+7XjnSp/j+VoyzsjYnfbYrDpbMQJl5bjOYgcE9mHmyzJg2Rj/8NC7s7gwZzbVL6ucR wdJRePvPdD0zeEDb72IQCOaVO2xdKALczqjhRBE2jKnCBeJMdycF9wdn1IIUbMfrWxzi v23CutFgBd3pxV1oiG0hGh5UdIj9KjKimNmimqnP67ZcrIJJJoDjCP4iZtyunMAv7XQz Nw5iS/lfnDEs+6vLCedfzow1BYMRIeaAFvRnnrVXUZ69l+4eCGYkCbnTfXNVKG8B5kJZ KYGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=sUCsDspGadsZLPl4FY9ZmW0mnOwrOlniPVvguok709M=; fh=dLWmFtfasJy2KRVD4WqGlPkStpiGWg2/pn78+IdJ6fw=; b=J5Qz1+B6e2t/Ya7a8dFhKAy97+uexxfJv8+PN+zTAh8JQtjBpO0JLrIFfVuQakYayU 2gQP/hq8qjwwR+U8WmC/eSitI0Qeef4UIIVsy1yxon8pkf8PpA1oJGrgY7tzr8NMSXVB KEaohApZoVPHQH9o3wCtv5lYcaO8eL8Kqh7++VBN8n5H03B42dScg1dmDTIc7lC99RhW lDSN7nZiCVpD76l3z07qxCNADZU6GLAhZaJaVEQew+X+efAQgfjM8uxG4G6NiN0HVTeo Kn8gA11BEIO1ibzqEKfDEhp2kt7EkOwETQkfQIf1CoCGnKnZRqvHqVAeCdM64OK4HGZe k/Qg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cmwJVU2f; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g8-20020a05620a218800b00774165a6970si6396532qka.488.2023.11.28.09.31.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 09:31:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cmwJVU2f; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEFAF388207A for ; Tue, 28 Nov 2023 17:31:29 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 037E138754AB for ; Tue, 28 Nov 2023 17:31:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 037E138754AB 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 037E138754AB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701192664; cv=none; b=wLgUA2VRInElZXfXsAWUKbiiRXF9WLqKODQzUPLMUZn4wzzq8C/iuQkB+lNdwZrTISlRd6zWNyRXhbF1SP5/7lGZEDXXEA52GKvy5S5NQypvrzyf1uycOQC56zlfcEKwFZ82KJGOqPKu64byEW4mPyKORF2+k46dBghtdhVaHmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701192664; c=relaxed/simple; bh=kR7UPj56kjvcTQaJ2pHRtDh+ZTJyCKL+vg6OAU5rOsE=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Kvdp/Ve6ET3EqTBB55Ulfdw/aY81r5wIGDeK3j54jXC1zKSQUJE4jisom8qB1AOqnQwy8LzHClMQj+uYumzk4sHwe71E+8si1v006xp9osgZ2/M5JtuZF6buXuEcqP6xyu5u3UWf0qDn4fQebMwL3xag7cKXhNJ6W9anH60vsvk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701192661; 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=sUCsDspGadsZLPl4FY9ZmW0mnOwrOlniPVvguok709M=; b=cmwJVU2feAZeIhZtLFIxWDr4IQ5rDjtFpv6ZlRQonZOe4fSFO/io3TziBil5oWG1yQGQl2 pyhxrApGhJp9/xUEWL/h5NzVuRIQbKZO2ecfhpxD+rfXbg52alqbBo43aN/YbE//DJvk2j rETSIxdTM438X9dOZcqzxcC//DijfGc= 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-271-9XDxa-D6PX6F0s_T_L1LHw-1; Tue, 28 Nov 2023 12:30:57 -0500 X-MC-Unique: 9XDxa-D6PX6F0s_T_L1LHw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 F0BAD3C0F425; Tue, 28 Nov 2023 17:30:56 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD5801121307; Tue, 28 Nov 2023 17:30:56 +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 3ASHUrBe759464 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Nov 2023 18:30:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3ASHUqn3759463; Tue, 28 Nov 2023 18:30:52 +0100 Date: Tue, 28 Nov 2023 18:30:52 +0100 From: Jakub Jelinek To: Manolis Tsamis , Jeff Law Cc: gcc-patches@gcc.gnu.org, Richard Biener , Vineet Gupta , Philipp Tomsich Subject: [PATCH] fold-mem-offsets, v2: Fix powerpc64le-linux profiledbootstrap [PR111601] Message-ID: References: <20231016180107.2019608-1-manolis.tsamis@vrull.eu> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783829827359064877 X-GMAIL-MSGID: 1783829827359064877 On Tue, Nov 28, 2023 at 02:19:36PM +0200, Manolis Tsamis wrote: > > So, like this (so far untested)? > > > > Note, the earlier posted patch passed bootstrap/regtest on > > {powerpc64le,x86_64,i686}-linux. Testing revealed this fails miserably, artificial uses don't really have DF_REF_INSN, so I'm now retrying with this which first punts on non-regular uses (hoping non-regular uses are always the same between -g and -g0) and only continuing on DEBUG_INSNs for the regular uses. 2023-11-28 Jakub Jelinek PR bootstrap/111601 * fold-mem-offsets.cc (get_uses): Ignore DEBUG_INSN uses. Otherwise, punt if use is in a different basic block from INSN or appears before INSN in the same basic block. Formatting fixes. (get_single_def_in_bb): Formatting fixes. (fold_offsets_1, pass_fold_mem_offsets::execute): Comment formatting fixes. * g++.dg/opt/pr111601.C: New test. Jakub --- gcc/fold-mem-offsets.cc.jj 2023-11-02 07:49:17.060865772 +0100 +++ gcc/fold-mem-offsets.cc 2023-11-28 11:47:34.941679105 +0100 @@ -154,7 +154,7 @@ static int stats_fold_count; The definition is desired for REG used in INSN. Return the definition insn or NULL if there's no definition with the desired criteria. */ -static rtx_insn* +static rtx_insn * get_single_def_in_bb (rtx_insn *insn, rtx reg) { df_ref use; @@ -205,11 +205,10 @@ get_single_def_in_bb (rtx_insn *insn, rt /* Get all uses of REG which is set in INSN. Return the use list or NULL if a use is missing / irregular. If SUCCESS is not NULL then set it to false if there are missing / irregular uses and true otherwise. */ -static struct df_link* +static df_link * get_uses (rtx_insn *insn, rtx reg, bool *success) { df_ref def; - struct df_link *ref_chain, *ref_link; if (success) *success = false; @@ -221,18 +220,30 @@ get_uses (rtx_insn *insn, rtx reg, bool if (!def) return NULL; - ref_chain = DF_REF_CHAIN (def); + df_link *ref_chain = DF_REF_CHAIN (def); + int insn_luid = DF_INSN_LUID (insn); + basic_block insn_bb = BLOCK_FOR_INSN (insn); - for (ref_link = ref_chain; ref_link; ref_link = ref_link->next) + for (df_link *ref_link = ref_chain; ref_link; ref_link = ref_link->next) { /* Problem getting a use for this instruction. */ if (ref_link->ref == NULL) return NULL; if (DF_REF_CLASS (ref_link->ref) != DF_REF_REGULAR) return NULL; + + rtx_insn *use = DF_REF_INSN (ref_link->ref); + if (DEBUG_INSN_P (use)) + continue; + /* We do not handle REG_EQUIV/REG_EQ notes for now. */ if (DF_REF_FLAGS (ref_link->ref) & DF_REF_IN_NOTE) return NULL; + if (BLOCK_FOR_INSN (use) != insn_bb) + return NULL; + /* Punt if use appears before def in the basic block. See PR111601. */ + if (DF_INSN_LUID (use) < insn_luid) + return NULL; } if (success) @@ -255,8 +266,7 @@ fold_offsets (rtx_insn *insn, rtx reg, b If DO_RECURSION is true and ANALYZE is false then offset that would result from folding is computed and is returned through the pointer OFFSET_OUT. - The instructions that can be folded are recorded in FOLDABLE_INSNS. -*/ + The instructions that can be folded are recorded in FOLDABLE_INSNS. */ static bool fold_offsets_1 (rtx_insn *insn, bool analyze, bool do_recursion, HOST_WIDE_INT *offset_out, bitmap foldable_insns) @@ -846,8 +856,8 @@ pass_fold_mem_offsets::execute (function FOR_ALL_BB_FN (bb, fn) { /* There is a conflict between this pass and RISCV's shorten-memrefs - pass. For now disable folding if optimizing for size because - otherwise this cancels the effects of shorten-memrefs. */ + pass. For now disable folding if optimizing for size because + otherwise this cancels the effects of shorten-memrefs. */ if (optimize_bb_for_size_p (bb)) continue; --- gcc/testsuite/g++.dg/opt/pr111601.C.jj 2023-11-27 21:33:12.605006881 +0100 +++ gcc/testsuite/g++.dg/opt/pr111601.C 2023-11-27 21:34:47.267678510 +0100 @@ -0,0 +1,86 @@ +// PR bootstrap/111601 +// { dg-do run { target c++11 } } +// { dg-options "-O2 -fno-exceptions -fno-rtti -fprofile-generate" } +// { dg-require-profiling "-fprofile-generate" } +// { dg-final { cleanup-coverage-files } } + +struct tree_base +{ + int code:16; +}; +struct saved_scope +{ + void *pad[14]; + int x_processing_template_decl; +}; +struct saved_scope *scope_chain; +struct z_candidate +{ + tree_base *fn; + void *pad[11]; + z_candidate *next; + int viable; + int flags; +}; + +__attribute__((noipa)) struct z_candidate * +splice_viable (struct z_candidate *cands, bool strict_p, bool *any_viable_p) +{ + struct z_candidate *viable; + struct z_candidate **last_viable; + struct z_candidate **cand; + bool found_strictly_viable = false; + if (scope_chain->x_processing_template_decl) + strict_p = true; + viable = (z_candidate *) 0; + last_viable = &viable; + *any_viable_p = false; + cand = &cands; + while (*cand) + { + struct z_candidate *c = *cand; + if (!strict_p && (c->viable == 1 || ((int) (c->fn)->code) == 273)) + { + strict_p = true; + if (viable && !found_strictly_viable) + { + *any_viable_p = false; + *last_viable = cands; + cands = viable; + viable = (z_candidate *) 0; + last_viable = &viable; + } + } + if (strict_p ? c->viable == 1 : c->viable) + { + *last_viable = c; + *cand = c->next; + c->next = (z_candidate *) 0; + last_viable = &c->next; + *any_viable_p = true; + if (c->viable == 1) + found_strictly_viable = true; + } + else + cand = &c->next; + } + return viable ? viable : cands; +} + +int +main () +{ + saved_scope s{}; + scope_chain = &s; + z_candidate z[4] = {}; + z[0].next = &z[1]; + z[1].viable = 1; + z[1].next = &z[2]; + z[2].viable = 1; + z[2].next = &z[3]; + bool b; + z_candidate *c = splice_viable (&z[0], true, &b); + if (c != &z[1] || z[1].next != &z[2] || z[2].next) + __builtin_abort (); + return 0; +}