From patchwork Mon May 6 12:15:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1931936 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=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bEyOrYDg; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ZYfDr5cj; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bEyOrYDg; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ZYfDr5cj; 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 4VY0kR1nQZz1ydW for ; Mon, 6 May 2024 22:16:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 571D8385EC56 for ; Mon, 6 May 2024 12:16:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id D85413858D28 for ; Mon, 6 May 2024 12:15:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D85413858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D85413858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714997710; cv=none; b=rNjo6ut5MPx/im8ok9BILrvbctD4AE5y/S/u9uXq4JRkncL+61zur9F+hgdWXNFI4xCGobcCRLxNS2lgju/lmrbMguJ6q2pUrFY19+l1Oexljzxm6zGIjm1TR/psr6vKfihpcv9kt7EJNdhRar545KLpvPxMoin8fexYXZTG+Tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714997710; c=relaxed/simple; bh=2VA31GG/cB48e8KZqoI/3gz7L4pdDA8MzTENVWm52uE=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=dawJOvNAbkmK5Taj5cHLCFqjd0OtO+lPWm4A68e0q/dc0fwbRWyZZBRe6ngE6GBT2oEs7OtIDlWIKqedLkdgHRlBrN9y289hvleWb3VqtVfYKzR7t/XhGZFaFWUidk/REwcsZHS1yl1mkGFBLJZhfVbBTkwDHv3nL/tkk7Gxz3g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 94B715FCD9 for ; Mon, 6 May 2024 12:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714997706; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HS2/++aXUFac4gfHYq8sc1UHZw8EtFD4Op4riYyOfcc=; b=bEyOrYDgA7FlBUCPK9cumJSPwCB+LBtQsi6vAWWET0H9kvxuDeo2ysGKaQsi2kpdKPeSnO 0z02EYoN14ygP2KUPVle84OaPc194jTR4kI7gpZUhmIEZDXMvpz8FAoe29WgcRiP75uyp0 167U7gwUUjl6+OR7O1RsiJ//i5buWvE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714997706; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HS2/++aXUFac4gfHYq8sc1UHZw8EtFD4Op4riYyOfcc=; b=ZYfDr5cjTKSqTMcRaMFEYDJhT0/5+yIy0yNMzhG1T4+xpg+R89CRU23stOROolE3vUvm+v FhN+DqQ4LsL0gSCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714997706; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HS2/++aXUFac4gfHYq8sc1UHZw8EtFD4Op4riYyOfcc=; b=bEyOrYDgA7FlBUCPK9cumJSPwCB+LBtQsi6vAWWET0H9kvxuDeo2ysGKaQsi2kpdKPeSnO 0z02EYoN14ygP2KUPVle84OaPc194jTR4kI7gpZUhmIEZDXMvpz8FAoe29WgcRiP75uyp0 167U7gwUUjl6+OR7O1RsiJ//i5buWvE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714997706; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HS2/++aXUFac4gfHYq8sc1UHZw8EtFD4Op4riYyOfcc=; b=ZYfDr5cjTKSqTMcRaMFEYDJhT0/5+yIy0yNMzhG1T4+xpg+R89CRU23stOROolE3vUvm+v FhN+DqQ4LsL0gSCA== Date: Mon, 6 May 2024 14:15:06 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/100923 - re-do VN with contextual PTA info fix MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.46 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.70)[-0.697]; NEURAL_HAM_SHORT(-0.16)[-0.799]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-ssa-sccvn.cc:url] X-Spam-Score: -1.46 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240506121613.571D8385EC56@sourceware.org> The following implements the gist of the PR100923 fix in a leaner (and more complete) way by realizing that all ao_ref_init_from_vn_reference uses need to have an SSA name in the base valueized with availability in mind. Instead of re-valueizing the whole chain of operands we can simply only and always valueize the SSA name we put in the base. This handles also two omitted places in vn_reference_lookup_3. Bootstrapped and tested on x86_64-unknown-linux-gnu, will push later. Richard. PR tree-optimization/100923 * tree-ssa-sccvn.cc (ao_ref_init_from_vn_reference): Valueize base SSA_NAME. (vn_reference_lookup_3): Adjust vn_context_bb around calls to ao_ref_init_from_vn_reference. (vn_reference_lookup_pieces): Revert original PR100923 fix. (vn_reference_lookup): Likewise. --- gcc/tree-ssa-sccvn.cc | 58 +++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index fbbfa557833..726e9d88b8f 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -1201,11 +1201,17 @@ ao_ref_init_from_vn_reference (ao_ref *ref, case STRING_CST: /* This can show up in ARRAY_REF bases. */ case INTEGER_CST: - case SSA_NAME: *op0_p = op->op0; op0_p = NULL; break; + case SSA_NAME: + /* SSA names we have to get at one available since it contains + flow-sensitive info. */ + *op0_p = vn_valueize (op->op0); + op0_p = NULL; + break; + /* And now the usual component-reference style ops. */ case BIT_FIELD_REF: offset += wi::to_poly_offset (op->op1); @@ -2725,7 +2731,6 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, copy_reference_ops_from_ref (lhs, &lhs_ops); valueize_refs_1 (&lhs_ops, &valueized_anything, true); } - vn_context_bb = saved_rpo_bb; ao_ref_init (&lhs_ref, lhs); lhs_ref_ok = true; if (valueized_anything @@ -2734,9 +2739,11 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, ao_ref_base_alias_set (&lhs_ref), TREE_TYPE (lhs), lhs_ops) && !refs_may_alias_p_1 (ref, &lhs_ref, data->tbaa_p)) { + vn_context_bb = saved_rpo_bb; *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE; return NULL; } + vn_context_bb = saved_rpo_bb; /* When the def is a CLOBBER we can optimistically disambiguate against it since any overlap it would be undefined behavior. @@ -3634,13 +3641,19 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, /* Adjust *ref from the new operands. */ ao_ref rhs1_ref; ao_ref_init (&rhs1_ref, rhs1); + basic_block saved_rpo_bb = vn_context_bb; + vn_context_bb = gimple_bb (def_stmt); if (!ao_ref_init_from_vn_reference (&r, force_no_tbaa ? 0 : ao_ref_alias_set (&rhs1_ref), force_no_tbaa ? 0 : ao_ref_base_alias_set (&rhs1_ref), vr->type, vr->operands)) - return (void *)-1; + { + vn_context_bb = saved_rpo_bb; + return (void *)-1; + } + vn_context_bb = saved_rpo_bb; /* This can happen with bitfields. */ if (maybe_ne (ref->size, r.size)) { @@ -3839,8 +3852,14 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, return data->finish (0, 0, val); /* Adjust *ref from the new operands. */ + basic_block saved_rpo_bb = vn_context_bb; + vn_context_bb = gimple_bb (def_stmt); if (!ao_ref_init_from_vn_reference (&r, 0, 0, vr->type, vr->operands)) - return (void *)-1; + { + vn_context_bb = saved_rpo_bb; + return (void *)-1; + } + vn_context_bb = saved_rpo_bb; /* This can happen with bitfields. */ if (maybe_ne (ref->size, r.size)) return (void *)-1; @@ -3928,31 +3947,13 @@ vn_reference_lookup_pieces (tree vuse, alias_set_type set, unsigned limit = param_sccvn_max_alias_queries_per_access; vn_walk_cb_data data (&vr1, NULL_TREE, NULL, kind, true, NULL_TREE, false); - vec ops_for_ref; - if (!valueized_p) - ops_for_ref = vr1.operands; - else - { - /* For ao_ref_from_mem we have to ensure only available SSA names - end up in base and the only convenient way to make this work - for PRE is to re-valueize with that in mind. */ - ops_for_ref.create (operands.length ()); - ops_for_ref.quick_grow (operands.length ()); - memcpy (ops_for_ref.address (), - operands.address (), - sizeof (vn_reference_op_s) - * operands.length ()); - valueize_refs_1 (&ops_for_ref, &valueized_p, true); - } if (ao_ref_init_from_vn_reference (&r, set, base_set, type, - ops_for_ref)) + vr1.operands)) *vnresult = ((vn_reference_t) walk_non_aliased_vuses (&r, vr1.vuse, true, vn_reference_lookup_2, vn_reference_lookup_3, vuse_valueize, limit, &data)); - if (ops_for_ref != shared_lookup_references) - ops_for_ref.release (); gcc_checking_assert (vr1.operands == shared_lookup_references); if (*vnresult && data.same_val @@ -4053,18 +4054,9 @@ vn_reference_lookup (tree op, tree vuse, vn_lookup_kind kind, vn_reference_t wvnresult; ao_ref r; unsigned limit = param_sccvn_max_alias_queries_per_access; - auto_vec ops_for_ref; - if (valueized_anything) - { - copy_reference_ops_from_ref (op, &ops_for_ref); - bool tem; - valueize_refs_1 (&ops_for_ref, &tem, true); - } - /* Make sure to use a valueized reference if we valueized anything. - Otherwise preserve the full reference for advanced TBAA. */ if (!valueized_anything || !ao_ref_init_from_vn_reference (&r, vr1.set, vr1.base_set, - vr1.type, ops_for_ref)) + vr1.type, vr1.operands)) { ao_ref_init (&r, op); /* Record the extra info we're getting from the full ref. */