From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from moene.org (84-86-97-173.fixed.kpn.net [84.86.97.173]) by sourceware.org (Postfix) with ESMTPS id 5A9113858D20 for ; Sat, 10 Feb 2024 21:20:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A9113858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=moene.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=moene.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5A9113858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=84.86.97.173 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707600046; cv=none; b=nQa22wIKiGLA+I3Ltfp/+DwFZlUgeZ1wFcMlwPGy45zv53g7UEN7kPH1JJkonY/69lgFU/2A3Y+Ba9jDioc2AuQjD0E3RJ11y+N0n3sig1g18IC9pf6YQHJhvCuPCfWjXiHRMEAHFNyETvzLl0673+vmxzBInk64qjbhCVv0pvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707600046; c=relaxed/simple; bh=PPNLuDXzdkriVDl4yuohFppVPViLMSmGv4s1Z5pSKVo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=i+py9+wgg0udkF/U0eV2dYi9HcEqGjarbf2x1wWZIx/WS+Ys7F2Q1yjrdqa9jS4HU9PRiAgpMqfIKydUNYs6JyvnblnTuo1F4q3efAbz2YQOED/TboS0gipCtBSYnfPa4ntlKVdXXF/LUY50t5f4R2arDILGNavJ/QX5GvN5TPI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=moene.org; s=key; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References: Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=fQpROlH+Hxg19IBawRTmgetoE2yd5RQjmcfhizLKNvA=; b=sm/ks8SZA4ar8kVsdMUX89KEAI A6MfT6IB8inxKoEG7fXdmfY3wuqFwMXEUdW9O1EGGl+KI4DqPzrtSFnxaH6GZRkWLjv5vSM8+hpO8 I/65Nm6QzusAAMXfYZ2FogRI3Fi3VYVt/eVq7RgrW5arAYcUEDkffiFTQCdu2wyugFaBIwYJyz8PZ rvw0yjK6ngE/4zbDPqAz7zCTSxbifbLihUYHscBt92E5euGW+oqmwxNwbzj2ctTJTZzSuAB2G839x v3D5auOxZ4+0DRtDyOqPkUxN7pBWh27gHOwud+w3uQFlk0LO6/Zo4/EzyzwKFDnSYlnYnxo2d1Teh E2BLmPsg==; Received: from localhost ([127.0.0.1]) by moene.org with esmtp (Exim 4.97) (envelope-from ) id 1rYumB-0000000GDXn-1Ec6; Sat, 10 Feb 2024 22:20:43 +0100 Message-ID: Date: Sat, 10 Feb 2024 22:20:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] rtl-optimization/113597 - recover base term for argument pointers Content-Language: en-US To: Richard Biener , gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com References: <20240209102637.6BB1D3858438@sourceware.org> From: Toon Moene Organization: Moene Computational Physics, Maartensdijk, The Netherlands In-Reply-To: <20240209102637.6BB1D3858438@sourceware.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 List-Id: I managed to try this patch on aarch64-linux-gnu: This is the test run without your patch: https://gcc.gnu.org/pipermail/gcc-testresults/2024-February/807637.html And this is the "result" with your patch: https://gcc.gnu.org/pipermail/gcc-testresults/2024-February/807645.html For me, as for you, it works for x86_64-linux-gnu: https://gcc.gnu.org/pipermail/gcc-testresults/2024-February/807609.html I hope this helps. Kind regards, Toon Moene. On 2/9/24 11:26, Richard Biener wrote: > The following allows a base term to be derived from an existing > MEM_EXPR, notably the points-to set of a MEM_REF base. For the > testcase in the PR this helps RTL DSE elide stores to a stack > temporary. This covers pointers to NONLOCAL which can be mapped > to arg_base_value, helping to disambiguate against other special > bases (ADDRESS) as well as PARM_DECL accesses. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > This is an attempt to recover some of the losses from dumbing down > find_base_{term,value}. I did give my ideas how to properly do > this during stage1 a start, I will post a short incomplete RFC series > later today. > > OK for trunk? > > I've included all languages in testing and also tested with -m32 but > details of RTL alias analysis might escape me ... > > Thanks, > Richard. > > PR rtl-optimization/113597 > * alias.cc (find_base_term): Add argument for the whole mem > and derive a base term from its MEM_EXPR. > (true_dependence_1): Pass down the MEMs to find_base_term. > (write_dependence_p): Likewise. > (may_alias_p): Likewise. > --- > gcc/alias.cc | 43 ++++++++++++++++++++++++++++++++++++------- > 1 file changed, 36 insertions(+), 7 deletions(-) > > diff --git a/gcc/alias.cc b/gcc/alias.cc > index 6fad4b29d31..e33c56b0e80 100644 > --- a/gcc/alias.cc > +++ b/gcc/alias.cc > @@ -40,6 +40,9 @@ along with GCC; see the file COPYING3. If not see > #include "rtl-iter.h" > #include "cgraph.h" > #include "ipa-utils.h" > +#include "stringpool.h" > +#include "value-range.h" > +#include "tree-ssanames.h" > > /* The aliasing API provided here solves related but different problems: > > @@ -190,6 +193,10 @@ static struct { > arguments, since we do not know at this level whether accesses > based on different arguments can alias. The ADDRESS has id 0. > > + This is solely useful to disambiguate against other ADDRESS > + bases as we know incoming pointers cannot point to local > + stack, frame or argument space. > + > 2. stack_pointer_rtx, frame_pointer_rtx, hard_frame_pointer_rtx > (if distinct from frame_pointer_rtx) and arg_pointer_rtx. > Each of these rtxes has a separate ADDRESS associated with it, > @@ -2113,12 +2120,34 @@ find_base_term (rtx x, vec to avoid visiting them multiple times. We unwind that changes here. */ > > static rtx > -find_base_term (rtx x) > +find_base_term (rtx x, const_rtx mem = NULL_RTX) > { > auto_vec, 32> visited_vals; > rtx res = find_base_term (x, visited_vals); > for (unsigned i = 0; i < visited_vals.length (); ++i) > visited_vals[i].first->locs = visited_vals[i].second; > + if (!res && mem && MEM_EXPR (mem)) > + { > + tree base = get_base_address (MEM_EXPR (mem)); > + if (TREE_CODE (base) == PARM_DECL > + && DECL_RTL_SET_P (base)) > + /* We need to look at how we expanded a PARM_DECL. It might be in > + the argument space (UNIQUE_BASE_VALUE_ARGP) or it might > + be spilled (UNIQUE_BASE_VALUE_FP/UNIQUE_BASE_VALUE_HFP). */ > + res = find_base_term (DECL_RTL (base)); > + else if (TREE_CODE (base) == MEM_REF > + && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME > + && SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))) > + { > + auto pt = &SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))->pt; > + if (pt->nonlocal > + && !pt->anything > + && !pt->escaped > + && !pt->ipa_escaped > + && bitmap_empty_p (pt->vars)) > + res = arg_base_value; > + } > + } > return res; > } > > @@ -3035,13 +3064,13 @@ true_dependence_1 (const_rtx mem, machine_mode mem_mode, rtx mem_addr, > if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x)) > return true; > > - base = find_base_term (x_addr); > + base = find_base_term (x_addr, x); > if (base && (GET_CODE (base) == LABEL_REF > || (GET_CODE (base) == SYMBOL_REF > && CONSTANT_POOL_ADDRESS_P (base)))) > return false; > > - rtx mem_base = find_base_term (true_mem_addr); > + rtx mem_base = find_base_term (true_mem_addr, mem); > if (! base_alias_check (x_addr, base, true_mem_addr, mem_base, > GET_MODE (x), mem_mode)) > return false; > @@ -3142,7 +3171,7 @@ write_dependence_p (const_rtx mem, > if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x)) > return true; > > - base = find_base_term (true_mem_addr); > + base = find_base_term (true_mem_addr, mem); > if (! writep > && base > && (GET_CODE (base) == LABEL_REF > @@ -3150,7 +3179,7 @@ write_dependence_p (const_rtx mem, > && CONSTANT_POOL_ADDRESS_P (base)))) > return false; > > - rtx x_base = find_base_term (true_x_addr); > + rtx x_base = find_base_term (true_x_addr, x); > if (! base_alias_check (true_x_addr, x_base, true_mem_addr, base, > GET_MODE (x), GET_MODE (mem))) > return false; > @@ -3265,8 +3294,8 @@ may_alias_p (const_rtx mem, const_rtx x) > if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x)) > return true; > > - rtx x_base = find_base_term (x_addr); > - rtx mem_base = find_base_term (mem_addr); > + rtx x_base = find_base_term (x_addr, x); > + rtx mem_base = find_base_term (mem_addr, mem); > if (! base_alias_check (x_addr, x_base, mem_addr, mem_base, > GET_MODE (x), GET_MODE (mem_addr))) > return false; -- Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290 Saturnushof 14, 3738 XG Maartensdijk, The Netherlands