From patchwork Mon Nov 27 23:51:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 170509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3553535vqx; Mon, 27 Nov 2023 15:51:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEElPO5fUl7VoC97McP2EO25TmESouYW0zClHKgZBReJADfIk7E/Yewjx2P4Wj8k4J3edU9 X-Received: by 2002:ac8:618c:0:b0:423:b6a1:206e with SMTP id kq12-20020ac8618c000000b00423b6a1206emr6053258qtb.5.1701129119365; Mon, 27 Nov 2023 15:51:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701129119; cv=pass; d=google.com; s=arc-20160816; b=dizXLuKzhzHvlIq8q4YQqlldT6XIDsYn86S9pEqsf3ZUxTBRTIyyjfYo0GGSSNIsip 8KUNzmQJQhkddEMFDe8bpIX0jzs3bCH4eYMnkN8mghIoX1cxAznMLjoT9zzV1L72JWPB A9GYoFTAIZb/MGOVcJVhLV/r+re/pm2pzgkfKH2nKd8ltN8nZ4FpmVJdCl7naqDFSo9Z gJcoOKuRz1g5MRsgvMx4GHu6DCcpxZsHnNI904MkA9L5oucglg5HlgU+USCtoYTrN6TS Q1GatyVG/HgkqkMOqUWeNj3touLVpS/XxGNX2Ij9nuRhIgYHKA2xwrIDqs2JFmhfkY/i /HjA== 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:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=tB4pjJzjh7O8MD7g9mvw2NNzJDp8/Q8Uz9YUopiqX9w=; fh=Q7pMWiVp+Cu2KKx0KFJaFIAidP/l9SV+Gy6UVy87ARE=; b=Z66DOyJESvmEn55I5alDDsuIaT6xOfUxdpm1q6AKeTUCKh/23aN3lLPqycXLIWcc06 ErB5lNjQKo0RHvqFkltMJxolxJ5mmsxQLL70LlkfmaHpfVifrDIc3rhVldaEkphJ4dw5 HhFP82xGozEEeq4u90Tiu0LOTs778Epu8he9QeKD26RQ5bOMKSDcP/ONZYAjWKabSWcH MobvAa6VUnz33ml6avk6d7JP7e1MaHm1k5iFxjZ9nlvib3iktNUtVM9oPEyH3CtU2ZqO GyaFAssIxfcjL2CqGvHK5iM8LflhUqWruHM8KJY8715W1zM1mQ08t1jUKJ0L3a8GsLRC 5HSw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zxe4EGbv; 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 t35-20020a05622a182300b00410a3b28d66si10315216qtc.538.2023.11.27.15.51.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 15:51:59 -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=Zxe4EGbv; 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 1BA833858432 for ; Mon, 27 Nov 2023 23:51:59 +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 CD8573858C36 for ; Mon, 27 Nov 2023 23:51:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD8573858C36 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 CD8573858C36 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=1701129095; cv=none; b=RSIjeL/Skog3FdW97gDc/tzdiqSapsTfJbRZMP9MNnVcorjsaVogkQBE0EC23Xdrg7iIVzvZByRxwdFuCsTT6Vqs3ak7NjOAUoEQghoZnug1qNWlK4a4QQpIyctRPHV5ewK21SEoi/fWh8oTPRyTvQVpgkMGDSt83ShMEvEfagA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701129095; c=relaxed/simple; bh=al8HBYoa0zEJwX5k9XVU2jC0nkxwLF6aHX/c+HOTsbA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=XAx5RJ7DRQHbl3RH0TrzvRaPB/pT/XbqmYpRUiGnSHAmuhLIr7swT+nOJUtHn4EBzaEqsg6QSgTMTBiIKCFHz2J5rxlzLcifDf6LCfGWpRO1BaiVsuJ/XaAoLpFAelr7VnmQWQ6hOCPejZqb8oh+8Rl1ZK7WG48t8+36PCeKpuU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701129089; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=tB4pjJzjh7O8MD7g9mvw2NNzJDp8/Q8Uz9YUopiqX9w=; b=Zxe4EGbvmrkX1f+Rq/oYqtOqrT2yYWB5m7nflr5AOkKaBST02I6gBl0n1NQAUTdyDEzovc xOwZoh3NOrjMTJITaeN/NK9Ykm3NHUXXRi7n7U9oCAmqVOPG3bS2oiL/0cMk+yhUbf7moi /jVRShKYCvvqZWpEZjQi9EJLzEm2Nh8= 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-275-17I36wC-NtKBQnhQb7Sq5w-1; Mon, 27 Nov 2023 18:51:26 -0500 X-MC-Unique: 17I36wC-NtKBQnhQb7Sq5w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 87D661C0518F; Mon, 27 Nov 2023 23:51:25 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F8D220268D2; Mon, 27 Nov 2023 23:51:25 +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 3ARNpMGf2973378 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Nov 2023 00:51:23 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3ARNpLGF2972985; Tue, 28 Nov 2023 00:51:21 +0100 Date: Tue, 28 Nov 2023 00:51:21 +0100 From: Jakub Jelinek To: Jeff Law , Manolis Tsamis , gcc-patches@gcc.gnu.org, Richard Biener , Vineet Gupta , Philipp Tomsich Subject: [PATCH] fold-mem-offsets: 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.4 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, KAM_SHORT, 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: 1783763167422255555 X-GMAIL-MSGID: 1783763167422255555 On Mon, Nov 27, 2023 at 09:52:14PM +0100, Jakub Jelinek wrote: > On Mon, Oct 16, 2023 at 01:11:01PM -0600, Jeff Law wrote: > > > gcc/ChangeLog: > > > > > > * Makefile.in: Add fold-mem-offsets.o. > > > * passes.def: Schedule a new pass. > > > * tree-pass.h (make_pass_fold_mem_offsets): Declare. > > > * common.opt: New options. > > > * doc/invoke.texi: Document new option. > > > * fold-mem-offsets.cc: New file. > > > > > > gcc/testsuite/ChangeLog: > > > > > > * gcc.target/riscv/fold-mem-offsets-1.c: New test. > > > * gcc.target/riscv/fold-mem-offsets-2.c: New test. > > > * gcc.target/riscv/fold-mem-offsets-3.c: New test. > > Thanks, I've pushed this to the trunk. > > This breaks profiledbootstrap on powerpc64le-linux. > >From what I can see, the pass works one basic block at a time and > will punt on any non-DEBUG_INSN uses outside of the current block > (I believe because of the > /* This use affects instructions outside of CAN_FOLD_INSNS. */ > if (!bitmap_bit_p (&can_fold_insns, INSN_UID (use))) > return 0; > test and can_fold_insns only set in do_analysis (when processing insns in > current bb, cleared at the end) or results of get_single_def_in_bb > (which are checked to be in the same bb). > But, while get_single_def_in_bb checks for > if (DF_INSN_LUID (def) > DF_INSN_LUID (insn)) > return NULL; > (OT, why not DF_INSN_INFO_LUID (DF_REF_INSN_INFO (ref_chain->ref)) > instead of DF_INSN_LUID (def), then it doesn't need to look up > DF_INSN_INFO_GET (def)?), nothing when walking all uses of def does such > luid check. > The basic block in the PR in question has: > ... > (insn 212 210 215 25 (set (mem/f:DI (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) [2 *last_viable_336+0 S8 A64]) > (reg/f:DI 9 9 [orig:155 _342 ] [155])) "pr111601.ii":50:17 683 {*movdi_internal64} > (expr_list:REG_DEAD (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) > (nil))) > (insn 215 212 484 25 (set (reg:DI 5 5 [226]) > (const_int 0 [0])) "pr111601.ii":52:12 683 {*movdi_internal64} > (expr_list:REG_EQUIV (const_int 0 [0]) > (nil))) > (insn 484 215 218 25 (set (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) > (reg/f:DI 9 9 [orig:155 _342 ] [155])) "pr111601.ii":52:12 683 {*movdi_internal64} > (nil)) > ... > (insn 564 214 216 25 (set (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) > (plus:DI (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) > (const_int 96 [0x60]))) "pr111601.ii":52:12 66 {*adddi3} > (nil)) > (insn 216 564 219 25 (set (mem/f:DI (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) [2 _343->next+0 S8 A64]) > (reg:DI 5 5 [226])) "pr111601.ii":52:12 683 {*movdi_internal64} > (expr_list:REG_DEAD (reg:DI 5 5 [226]) > (nil))) > ... > and when asking for all uses of %r10 from def 564, it will see uses > in 216 and 212; the former is after the += 96 addition and gets changed > to load from %r10+96 with the addition being dropped, but there is > the other store which is a use across the backedge and when reached > from other edges certainly doesn't have the + 96 addition anywhere, > so the pass doesn't actually change that location. > > Haven't bootstrapped/regtested this yet, will start momentarily, > posting here just in case I'm missing something important. That version failed bootstrap because DF_INSN_LUID is signed int, not unsigned. Here is what so far passed on powerpc64le-linux ../configure --enable-languages=c,c++ --enable-checking=yes,rtl,extra --disable-libsanitizer --with-long-double-128 make -j160 profiledbootstrap which has been failing for more than a month now. I've noticed a couple of small formatting issues and fixed them too, doing normal {powerpc64le,x86_64,i686}-linux bootstraps/regtests: 2023-11-27 Jakub Jelinek PR bootstrap/111601 * fold-mem-offsets.cc (fold_offsets): Punt if use appears before def in the basic block. (get_single_def_in_bb, get_uses): 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-27 22:47:21.128591332 +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,7 +205,7 @@ 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 struct df_link * get_uses (rtx_insn *insn, rtx reg, bool *success) { df_ref def; @@ -255,8 +255,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) @@ -511,6 +510,7 @@ fold_offsets (rtx_insn *insn, rtx reg, b if (!success) return 0; + int luid = DF_INSN_LUID (def); for (ref_link = uses; ref_link; ref_link = ref_link->next) { rtx_insn *use = DF_REF_INSN (ref_link->ref); @@ -534,6 +534,11 @@ fold_offsets (rtx_insn *insn, rtx reg, b if (use_set && MEM_P (SET_DEST (use_set)) && reg_mentioned_p (dest, SET_SRC (use_set))) return 0; + + /* Punt if use appears before def in the basic block. See + PR111601. */ + if (DF_INSN_LUID (use) < luid) + return 0; } bitmap_set_bit (&can_fold_insns, INSN_UID (def)); @@ -846,8 +851,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; +}