From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 26EFE3858D1E for ; Thu, 9 Nov 2023 12:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26EFE3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 26EFE3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699534507; cv=none; b=EPSjJC5QX8BsnRuiicsDWa5q4icOTGRSSM2I0OcXfXnqaSEfvClwiSCSCgxTmFpBxVx9kboQ3t8k0UJ5t2w4+Zj1uxMII0ZFjd9YYYwGmW4qLuWnXtg/sGezqiJPz/LyPksWmh1/KHp549CzOQ1dCPr+N/GzxYnYaSAc/7/d8XI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699534507; c=relaxed/simple; bh=NQO7bthDtURhNXkwG0UrCcgfUv5aTiIO1Fj49P+KEOE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=owyC++ku4hIpfgiqAuNE2OMFjVct5J59LWsheplwpb2ZWJLd9d4u2g1zEjvUBpJCyCG5A3i4iWwKMNraLJkBURGHedt1L63VyNQSk9K8IdQKf6PM8bP4cATeVRjb9k4+rG27aa2fOArg77xrfhGXtLFYLxZEVZqzJtx9e8j9yZk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-5098fb403a2so632447e87.2 for ; Thu, 09 Nov 2023 04:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699534504; x=1700139304; 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=2pRDWL4tOBtb9ld6Vg0aVk3gpyPt4jqYlhJz4f3/bAY=; b=eIfHcKSlnUvQugjYbRUCU6QDc2lgDYW3x8qO2ZjD8MWrgvshs+KkYB86gDUanjP3q4 c7dsBiggyb0LNa58BHAEl9mleIOSSKcJ6rYeBGhvdAFNlI98qZR9AE6mucjV234iRJzj 9QjSjrh5eQGzxPEqn5r+xwCqOdD1eCUlYBnB9gpQsZr6ccDDjlEK5/8X9kzCe/AZFEcm 9XuJqOzZEgTehLdqfHU/w8frns5+mnV9FX8WgTeorAtEUmE1o0aDfucXZ2ZnUyPKHFq7 FtmxAWznmqwvMhJRwbAN0C0z8K06knpr5bsMLgMVENjLz2u7nSg0mKjcFu+O5qf9Aojy hChg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699534504; x=1700139304; 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=2pRDWL4tOBtb9ld6Vg0aVk3gpyPt4jqYlhJz4f3/bAY=; b=U2iyK33SuGnycdpUaSlhzPaaM/Jon48IqUCIq0kqKx4fwLgcezmu+FRWKhIDiE9uBQ oS0VnP19HM6NQwuOETbKESufqKctqsyawkAhd8N0CxJ9UcA12PAneo76T+7UE34b7b0Q 63OKdhNenJielid+/xCE4spBtsKH7tj3eY54wua9xZ+9jhFejCHdiyySZdQWxx8USAgW bJCrY4N3ct8lBZjP/HHcoYXzYb5wyEwSZ+pdSORNWwlX0WAkhtvaCBegd6jvSNxbx2Pz mAHUS+BVBsM/qJdBqsVfpdbqhDLUeIX78Ycbx+ZtqOn8Id2OFsE6JczuKNMbBpJ/ca/g LOEQ== X-Gm-Message-State: AOJu0Yy4yAVShDJnhHNm4RNnSubcmESe3Jm+Notp3QqTKp4SGYZ0w5Ow YgrEll//MP20qETzUHpy+T9Kyq9VYF3yso2v1OrlWCEM X-Google-Smtp-Source: AGHT+IHEGFjcHthM8o5TJUzyvy4tBpwSVkXYuyzSMb2GqLPhWR/J1ME0WjNDYWMtwYygQG5mPFWZhLlbMwWtxc1z2nU= X-Received: by 2002:a19:a419:0:b0:504:3a3d:5015 with SMTP id q25-20020a19a419000000b005043a3d5015mr1422415lfc.27.1699534503835; Thu, 09 Nov 2023 04:55:03 -0800 (PST) MIME-Version: 1.0 References: <908bdc21-ea98-436e-9566-01e4d8da9132@linux.ibm.com> In-Reply-To: <908bdc21-ea98-436e-9566-01e4d8da9132@linux.ibm.com> From: Richard Biener Date: Thu, 9 Nov 2023 13:51:39 +0100 Message-ID: Subject: Re: [PATCH] tree-ssa-loop-ivopts : Add live analysis in regs used in decision making To: Ajit Agarwal Cc: Jeff Law , Peter Bergner , gcc-patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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 Wed, Nov 8, 2023 at 4:00=E2=80=AFPM Ajit Agarwal wrote: > > tree-ssa-loop-ivopts : Add live analysis in regs used in decision making. > > Add live anaysis in regs used calculation in decision making of > selecting ivopts candidates. > > 2023-11-08 Ajit Kumar Agarwal > > gcc/ChangeLog: > > * tree-ssa-loop-ivopts.cc (get_regs_used): New function. > (determine_set_costs): Call to get_regs_used to use live > analysis. > --- > gcc/tree-ssa-loop-ivopts.cc | 73 +++++++++++++++++++++++++++++++++++-- > 1 file changed, 70 insertions(+), 3 deletions(-) > > diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc > index c3336603778..e02fe7d434b 100644 > --- a/gcc/tree-ssa-loop-ivopts.cc > +++ b/gcc/tree-ssa-loop-ivopts.cc > @@ -6160,6 +6160,68 @@ ivopts_estimate_reg_pressure (struct ivopts_data *= data, unsigned n_invs, > return cost + n_cands; > } > > +/* Return regs used based on live-in and liveout of given ssa variables.= */ Please explain how the following code relates to anything like "live analysis" and where it uses live-in and live-out. And what "live-in/out of a given SSA variable" should be. Also explain why you are doing this at all. The patch doesn't come with a testcase or with any other hint that motivated you. Richard. > +static unsigned > +get_regs_used (tree ssa_name) > +{ > + unsigned regs_used =3D 0; > + gimple *stmt; > + use_operand_p use; > + basic_block def_bb =3D NULL; > + imm_use_iterator imm_iter; > + > + stmt =3D SSA_NAME_DEF_STMT (ssa_name); > + if (stmt) > + { > + def_bb =3D gimple_bb (stmt); > + /* Mark defs in liveout bitmap temporarily. */ > + if (def_bb) > + regs_used++; > + } > + else > + def_bb =3D ENTRY_BLOCK_PTR_FOR_FN (cfun); > + > + /* An undefined local variable does not need to be very alive. */ > + if (virtual_operand_p (ssa_name) > + || ssa_undefined_value_p (ssa_name, false)) > + return 0; > + > + /* Visit each use of SSA_NAME and if it isn't in the same block as the= def, > + add it to the list of live on entry blocks. */ > + FOR_EACH_IMM_USE_FAST (use, imm_iter, ssa_name) > + { > + gimple *use_stmt =3D USE_STMT (use); > + basic_block add_block =3D NULL; > + > + if (gimple_code (use_stmt) =3D=3D GIMPLE_PHI) > + { > + /* Uses in PHI's are considered to be live at exit of the SRC b= lock > + as this is where a copy would be inserted. Check to see if = it is > + defined in that block, or whether its live on entry. */ > + int index =3D PHI_ARG_INDEX_FROM_USE (use); > + edge e =3D gimple_phi_arg_edge (as_a (use_stmt), index= ); > + if (e->src !=3D def_bb) > + add_block =3D e->src; > + } > + else if (is_gimple_debug (use_stmt)) > + continue; > + else > + { > + /* If its not defined in this block, its live on entry. */ > + basic_block use_bb =3D gimple_bb (use_stmt); > + if (use_bb !=3D def_bb) > + add_block =3D use_bb; > + } > + > + /* If there was a live on entry use, increment register used. */ > + if (add_block) > + { > + regs_used++; > + } > + } > + return regs_used; > +} > + > /* For each size of the induction variable set determine the penalty. *= / > > static void > @@ -6200,15 +6262,20 @@ determine_set_costs (struct ivopts_data *data) > n++; > } > > + unsigned max =3D 0; > EXECUTE_IF_SET_IN_BITMAP (data->relevant, 0, j, bi) > { > struct version_info *info =3D ver_info (data, j); > - > if (info->inv_id && info->has_nonlin_use) > - n++; > + { > + tree ssa_name =3D ssa_name (j); > + n =3D get_regs_used (ssa_name); > + if (n >=3D max) > + max =3D n; > + } > } > > - data->regs_used =3D n; > + data->regs_used =3D max; > if (dump_file && (dump_flags & TDF_DETAILS)) > fprintf (dump_file, " regs_used %d\n", n); > > -- > 2.39.3 > >