From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 6CED73858D33 for ; Fri, 10 Nov 2023 14:00:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CED73858D33 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 6CED73858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699624810; cv=none; b=Cpd4XaRmcBHc0TvHOZg7J+97oU706k1LqBtnnLDSfkzOkjA9ZJ9Rhhu/1s7v3k9otFgfpYsY2k7jGx54PWIYZxfKlZfYNiGAUi71dLrvKjFnfXKmXmptFfT1NzDlfXasS5g1U9xcGFsypmxMqYVIoNpj9K2c0KbXfZSJA99hjYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699624810; c=relaxed/simple; bh=xruh3HX5hHLkU+hC4gTqagI1G19fcJjMMSJU8Llyazs=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=I4o3wJ0myDfXWBnim4j+2Px3uRXW4Bz2qSpxHKiG492Q39+Aro/QYjy4o6ErG8cqjH3a5lbqEiH7y+L3VnPSIevqbb5A4rwihFon9FxxFcTlFj7p/C5sBSzaNjsW+zRcIVTIGiboCN7W4hLZCUKYzQGJgLcgn6eCcZEUHxl+Njk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c5028e5b88so28141421fa.3 for ; Fri, 10 Nov 2023 06:00:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699624807; x=1700229607; 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=lcqPXdtm56TWv6Gk6qfcbEvNSOju0K7AEAx2hhuQesg=; b=kSIR+09gDGXMTiAmBEQ0ucNIUJc+vidC0xv9JItzxocGTL9uX5X78nLY/okNrWGAYW aXZSTkFR+C2RPNZeJ50t1gQHrsR6ObsnuNvk+tlb+NPsbkcA6/PzmyBjxLVOiE+7afXd K/WL8sYwEyyxbBoNFHmVaVJXKryujDfuqnk4LiIU24sUzFJW7e6GU4lzP1BzTpQFA+9i Zb01gXOLHkxirL/NtGXk/dx7FccLSRqXmAzX/aCG8Gzi23JkpYK4WdPgFHWXbkUExbsg hfuOUjO3Hru46uXxLyu0klq6rUdiO+u7cfyvI9ttpM4A2CvvnR2GTtBKy9xwOqiNFJ5v rlxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699624807; x=1700229607; 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=lcqPXdtm56TWv6Gk6qfcbEvNSOju0K7AEAx2hhuQesg=; b=qL0X23X8FVRLXTzsHKkqaSoqqdxnfnq9T4WAPK4tk1Qx5/HN+lCmBnwqaw4ql1wKzV RpWxEmxSCnOy65fNlGADVTvhUUTagjx4qYBcK2MtOMt5Mpe96mRyk5DPXJAX4GBO2VdZ eqspWF2HO0bTAocMeyLzauXR7Nz7cE94dH/BjVugLwyo0EePYm33OKKC1gkdrOTq2s6k nwlgvhbY5Kq5ZciXmq+ZuJtmtbbycAbb+pJPXvLmsBKhMqYraeknFdBGqV/ualCZYtcF MsIdYz/l8l18hrT1hEzoyP9kgFkc4kiN2qOvdN257aVE7wFjywMZ6/+wwjLOAarFNcrD CpGA== X-Gm-Message-State: AOJu0Yz42LRIOmm7p2xKhqEjmhnCp8QEnMLVvhc2rUUYcLn8EAjkemZw XeSLoiJs7OGPCPjQdGoGyjF59f0HWLICIwmfjw8= X-Google-Smtp-Source: AGHT+IGOolsNyPtf43xeWCb6jtPPXtJctXSj4xpP2UnRcYu2/R4Jw9sbIHsBopU+NNNurp4r4W36B5p1/71ZcXP+BVo= X-Received: by 2002:a05:6512:e83:b0:50a:5df2:f30f with SMTP id bi3-20020a0565120e8300b0050a5df2f30fmr2094606lfb.43.1699624806337; Fri, 10 Nov 2023 06:00:06 -0800 (PST) MIME-Version: 1.0 References: <908bdc21-ea98-436e-9566-01e4d8da9132@linux.ibm.com> <45fa6563-42a9-4442-8b36-f243417459c6@linux.ibm.com> In-Reply-To: <45fa6563-42a9-4442-8b36-f243417459c6@linux.ibm.com> From: Richard Biener Date: Fri, 10 Nov 2023 14:59:54 +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.3 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 Fri, Nov 10, 2023 at 7:42=E2=80=AFAM Ajit Agarwal wrote: > > Hello Richard: > > > On 09/11/23 6:21 pm, Richard Biener wrote: > > 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 maki= ng. > >> > >> 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_dat= a *data, unsigned n_invs, > >> return cost + n_cands; > >> } > >> > >> +/* Return regs used based on live-in and liveout of given ssa variabl= es. */ > > > > 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. > > > > The function get_regs_used increments the regs_used based on live-in > and live-out analysis of given ssa name. Instead of setting live-in and > live-out bitmap I increment the regs_used. > > Below is how I identify live-in and live-out and increments the regs_used > variable: > > a) For a given def_bb of gimple statement of ssa name there should be > live-out and increments the regs_used. > > b) Visit each use of SSA_NAME and if it isn't in the same block as the de= f, > we identify live on entry blocks and increments regs_used. > > The below function is the modification of set_var_live_on_entry of tree-s= sa-live.cc > Where we set the bitmap of liveout and livein of basic block. Instead of = setting bitmap, regs_used is incremented. It clearly doesn't work that way, and the number doesn't in any way relate = to the number of registers used or register pressure. > I identify regs_used as the number of live-in and liveout of given ssa na= me variable. > > For each iv candiate ssa variables I identify regs_used and take maximum = of regs > used for all the iv candidates that will be used in ivopts_estimate_regis= ter_pressure > cost analysis. > > Motivation behind doing this optimization is I get good performance impro= vement > for several spec cpu 2017 benchmarks for FP and INT around 2% to 7%. An interesting GIGO effect. > Also setting regs_used as number of iv candiates, which is not > optimized and robust way of decision making for ivopts optimization I dec= ide > on live-in and live-out analysis which is more correct and appropriate wa= y of > identifying regs_used. > > And also there are no regressions in bootstrapped/regtested on powerpc64-= linux-gnu. > > Thanks & Regards > Ajit > > >> +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 SR= C block > >> + 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), in= dex); > >> + 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 > >> > >>