From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 3237E3858D32 for ; Mon, 12 Feb 2024 15:26:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3237E3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3237E3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707751580; cv=none; b=p4CWL/WPII/AN4N1U4deb1tWSMFdH3oEYEtTvoXxQe1zncWOYV5zxbEfAlwSyq719I+7TyFXwfk04Dt6+ARbZcGq5eI9p/GstLFN/tSYgCxMvlGhpXbCv/op3IA2d5JzVztxL9aofCqVOXfFWop42GEoPpvB9VddekwfQwsfULo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707751580; c=relaxed/simple; bh=FrGMb8A+jNsaCDRYtNyile+ICZ8paZftySseQWGHXLc=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=wNanD8yvo/0QldL0pKzrg0YeoEBBc/+W3oIdmZoPaWLhnUF8mTU39YoGgJmi4DXoL76LggmHsh+UzdcFnAdZA+jxk20rJHZd7tL50MMXQFbaBcEr51YhJOS9klE+9g1/YLPP4m1g8yDY+TUR5xQfGHkT6OBz+fQM2kbvycJEfWg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a38392b9917so419099266b.1 for ; Mon, 12 Feb 2024 07:26:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707751576; x=1708356376; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0rCe5eTFnB+UPDRXSj4p0HwfzDeOxNJtBXGnq91a9xM=; b=i+EcGzh4FQDW68T/qq/wL8FgMHLGZ0PWCvwuG8fbSEaU3Fy3RLRr+Azo5CFmgjDZJX H3VpEHDxf9uqAJ7GOObn+9rdHFvRwaJYHbGNb8YwjBFa63tQRIJ4iT5CwAJqsYMlhoeD EX++Qej1nritZN/PsufMyVgQFgqcxtfWD9oD8wTXWWmAG8f3gFp4hc3hO0kPuicbirHA Vo523XatMzjZvOLGteTAd6S6owYrRnth7HTIvuxcAIn7UQ0gV2O5jMXKQkofBS8XccKG yu7fyd3eEuF8SRxjnexAJYANuu+XoOChUdvCto/Qv1eTciMkfyOltaZjBvtpQUQK3lPQ Y/bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707751576; x=1708356376; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0rCe5eTFnB+UPDRXSj4p0HwfzDeOxNJtBXGnq91a9xM=; b=pdgP7BJmZsZCVqukIpE12EzcMjOFb4zkwNwXz7B+13DinXd8W1Mn0o3yu2o1gARbwC aLgGQcfWFfuAChzPTjs+MqDDIIIeQmPlWgNfmjQNeQ8myUFG+Nv6ruGeUId8xPoByMyM TrmdyuQRvcFQzNF/T1Q5Zjx5z1sVlnZ1UvM9YgnEAGQgLmh08ncW5ba7ZHL/IHry6xV4 erveuqa2rD+EvEXHJ9cYYYhecj5OD2kVDitVO9NaBCvB+jDDN+ljJkTQ2PYnJN6eiJQZ x7FPIbj+1bEJ5ygAmH+XtNQI/6ejPZ4h73pFTusp87vM8SoJW8UPUP0H6WIHe9JIOAd8 51wg== X-Forwarded-Encrypted: i=1; AJvYcCUjKxae5kDerwOcfrl4k4uD2QUFDG/1W7cMtUyC8YQLgd0muZ4vnrPxEUUsudn4jQyaPKWCaDRHYKlmWxsaTBsHl/pF04mjhw== X-Gm-Message-State: AOJu0YwbG9iDXb5M69wLzsyiYQxyetp6c+jEG2IxDBKo2NGJwVt4rrjV Rluwc3pMod/mDrDkmKmQIOG9xTjeELxVPxIEH37NgbPK0CT//s3SH5YTcqV5a4ln2Ibb8xhJy5x /hw1mE6d1NOGH2QFzUqyOMk9B63r5NxdJQ4to2k0m81m1KGeyshQ= X-Google-Smtp-Source: AGHT+IGt7HfAbRAc/wi5u/yTv9rS7YbLgdHUxex7MdK4JjqvyWWMNulCZLsc8dtGRp1g7FPkHV8R3685YrwHovA1pR0= X-Received: by 2002:a17:906:af87:b0:a38:33bb:a7f0 with SMTP id mj7-20020a170906af8700b00a3833bba7f0mr5253928ejb.58.1707751575661; Mon, 12 Feb 2024 07:26:15 -0800 (PST) MIME-Version: 1.0 References: <20240209102637.6BB1D3858438@sourceware.org> In-Reply-To: From: Christophe Lyon Date: Mon, 12 Feb 2024 16:26:08 +0100 Message-ID: Subject: Re: [PATCH] rtl-optimization/113597 - recover base term for argument pointers To: Richard Biener Cc: Toon Moene , Richard Biener , gcc-patches@gcc.gnu.org, jeffreyalaw@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: On Mon, 12 Feb 2024 at 09:00, Richard Biener w= rote: > > On Sat, Feb 10, 2024 at 10:21=E2=80=AFPM Toon Moene wrot= e: > > > > 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 > > Interesting .. this looks like a miscompile of stage2. Note that the Lin= aro > CI was happy: > > https://patchwork.sourceware.org/project/gcc/patch/20240209102649.09C5438= 58404@sourceware.org/ > Hi! Indeed this is NOT a bootstrap build, we only have such checks in postcommi= t CI. Thanks, Christophe > Richard. > > > 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 prob= lems: > > > > > > @@ -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_rt= x > > > (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 h= ere. */ > > > > > > static rtx > > > -find_base_term (rtx x) > > > +find_base_term (rtx x, const_rtx mem =3D NULL_RTX) > > > { > > > auto_vec, 32> visi= ted_vals; > > > rtx res =3D find_base_term (x, visited_vals); > > > for (unsigned i =3D 0; i < visited_vals.length (); ++i) > > > visited_vals[i].first->locs =3D visited_vals[i].second; > > > + if (!res && mem && MEM_EXPR (mem)) > > > + { > > > + tree base =3D get_base_address (MEM_EXPR (mem)); > > > + if (TREE_CODE (base) =3D=3D 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 =3D find_base_term (DECL_RTL (base)); > > > + else if (TREE_CODE (base) =3D=3D MEM_REF > > > + && TREE_CODE (TREE_OPERAND (base, 0)) =3D=3D SSA_NAME > > > + && SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))) > > > + { > > > + auto pt =3D &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 =3D arg_base_value; > > > + } > > > + } > > > return res; > > > } > > > > > > @@ -3035,13 +3064,13 @@ true_dependence_1 (const_rtx mem, machine_mod= e mem_mode, rtx mem_addr, > > > if (MEM_ADDR_SPACE (mem) !=3D MEM_ADDR_SPACE (x)) > > > return true; > > > > > > - base =3D find_base_term (x_addr); > > > + base =3D find_base_term (x_addr, x); > > > if (base && (GET_CODE (base) =3D=3D LABEL_REF > > > || (GET_CODE (base) =3D=3D SYMBOL_REF > > > && CONSTANT_POOL_ADDRESS_P (base)))) > > > return false; > > > > > > - rtx mem_base =3D find_base_term (true_mem_addr); > > > + rtx mem_base =3D 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) !=3D MEM_ADDR_SPACE (x)) > > > return true; > > > > > > - base =3D find_base_term (true_mem_addr); > > > + base =3D find_base_term (true_mem_addr, mem); > > > if (! writep > > > && base > > > && (GET_CODE (base) =3D=3D LABEL_REF > > > @@ -3150,7 +3179,7 @@ write_dependence_p (const_rtx mem, > > > && CONSTANT_POOL_ADDRESS_P (base)))) > > > return false; > > > > > > - rtx x_base =3D find_base_term (true_x_addr); > > > + rtx x_base =3D 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) !=3D MEM_ADDR_SPACE (x)) > > > return true; > > > > > > - rtx x_base =3D find_base_term (x_addr); > > > - rtx mem_base =3D find_base_term (mem_addr); > > > + rtx x_base =3D find_base_term (x_addr, x); > > > + rtx mem_base =3D 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 > >