From patchwork Wed Nov 8 15:00:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajit Agarwal X-Patchwork-Id: 163077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp969130vqo; Wed, 8 Nov 2023 07:01:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAyYT4VFzi2PPaXsi4TQ1y/Z+959KBLzZObE/FrTjMvewUBytiBm4zW+BLAPXG2W+LR/rC X-Received: by 2002:a67:c005:0:b0:45f:2a26:aa7d with SMTP id v5-20020a67c005000000b0045f2a26aa7dmr1809445vsi.15.1699455665057; Wed, 08 Nov 2023 07:01:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699455665; cv=pass; d=google.com; s=arc-20160816; b=0H4WRzXgU/Z+gFi01ocSOEwmIG5MXRK8Zvt1Fsg3Vw5TCgnFHyosBJXwtF7M2wJqFN DCZBEWJt/VPnfvMFT0Myzl6zwtVPfH++vOHSrhHlogAgDW3kk9DlExCH8Ap+ltq0OLDi kEfUfE6fPS+iI455MKkoZiCgpRChfBXrESoZrfifa7rLNtRj4MmdNmFAaTf211LkcU6N fHX/nXF8ecedjkCnoXSN64T+5ATDYOXxiuPuis1jzMO2Qwue71q2WRaBC6K8crSs7b+c jT00tp4Pv9aY0g0SL2OlwReqgqEiIjr6SPNCTPsVbMSENqTtLA8ohAOSRlZxKTCjW4Sn e0Tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :subject:from:to:content-language:user-agent:mime-version:date :message-id:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=l13qzCByoLrtBP1obmRNy8i/nxl8lvDO4SgEGV0MGxw=; fh=0V1NjbpgEUEPNiUM11GiZ38/a8tYQPmGi2KrZs2rX1s=; b=xUHcwsMClRW7K/+Wa7ML6hpKSGeMDPVq/hHeS7aW9pt7Lx+TtyX9xtJ9HoxsCXG+vm 5xs4KHZqH8Hc0VI4LSwBKFpAxHEEk1Ib53YCt6+KVsoMBh+ggQ9ZSDiYnSgWH/rf5EjU dzoCdBPkn4WIYygZy2jknQyfdyRvjOF7aN2borzh4DafyCqv8jDCx/VO7ywFHBnF2Eh1 rSYDnNmY/7Sj/qezsNL7NAvxF3Q2JgGjYKFxb02r9w7J0qloHBbee86v+mnvp7l2B3Kz kNXn2YpHHeGyiEHyw8g3ZUQ4nr2kHeUW3KM4dJJPhSbfi+AEqthWTfqGY74xJPH5waUb 8oNQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=O+lihGj3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p1-20020a056102200100b0045258ccd2casi1194670vsr.740.2023.11.08.07.01.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 07:01:05 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=O+lihGj3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F7B6385C6E2 for ; Wed, 8 Nov 2023 15:00:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id F08123858D1E for ; Wed, 8 Nov 2023 15:00:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F08123858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F08123858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699455633; cv=none; b=d1zi9r+O27jjq1b4XPBkBHH1tzJkyEvvuWWu+UXGcvVZNBoMYg0twJxE+9rIkpbbx3VUQu+hWTNMC8V6pUE/4Rr8wQy9JzvQvPqzS3wyp06ZzkqhZa8jvqLxXy3O8Yu1qe7vYunOYojC4r9JJH37woo3Hj6RTG/OsCyMOBClpyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699455633; c=relaxed/simple; bh=Gu5GaXyvb7yxYbMiQmjEuP7/DtxVQ6ryISy43d+9kU0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=YlYJWuk+lTM2CzRsO1PILYItr8GgqPm+kWwo7+4FhPjbx42IQx7vUtWq+Aiqto1341XEeRCNGSPzAlv4/afAd++STjIUHEEl+B+XyVzabGHB9jMF4jkxOp+ksBVd+U2hBP/LIcKHL1axlBe6dwoIZz68QdrvIntuhTBFIicZTQo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8EpVnL007332 for ; Wed, 8 Nov 2023 15:00:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : to : from : subject : content-type : content-transfer-encoding; s=pp1; bh=l13qzCByoLrtBP1obmRNy8i/nxl8lvDO4SgEGV0MGxw=; b=O+lihGj3P1cw5zL+T30mScYS1P771GoU8RRpGgwTrAoGw8meQh5vtTo4RGU0BerNi/gA O8aKkZmX057lnujmvc4VTj9z1L9avcavYTLUyRyiPeLSGY06bX5xr2Q//oSzVVgKyMms Ki9gHbFbRrm+qLXvWXlNl4YV88cmRsIUx7I5hrED8+f5FOzHkTAL3qFxUhxdocyYSQhi g2GtFtdXGSKMdRe2kTSx1Nk2n4gCaClTm6sqpNrk8RSF4OdWu7tUADigTTAMUExfKkCt ixMZYLx0A91rAinDndoSZtCcha1ye43C38f6DHW6PvANFMrhvmuEHcbLLr5dgTE5kNXp IQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8cayggra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 08 Nov 2023 15:00:30 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3A8EpZIk007650 for ; Wed, 8 Nov 2023 15:00:30 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8cayggq4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 15:00:30 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8EHhEB003431; Wed, 8 Nov 2023 15:00:29 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3u7w21wfft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 15:00:29 +0000 Received: from smtpav03.wdc07v.mail.ibm.com (smtpav03.wdc07v.mail.ibm.com [10.39.53.230]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A8F0SMM47644990 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Nov 2023 15:00:28 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 66E6158054; Wed, 8 Nov 2023 15:00:28 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A27A5805D; Wed, 8 Nov 2023 15:00:26 +0000 (GMT) Received: from [9.43.37.171] (unknown [9.43.37.171]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Nov 2023 15:00:25 +0000 (GMT) Message-ID: <908bdc21-ea98-436e-9566-01e4d8da9132@linux.ibm.com> Date: Wed, 8 Nov 2023 20:30:23 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Richard Biener , Jeff Law , Peter Bergner , gcc-patches From: Ajit Agarwal Subject: [PATCH] tree-ssa-loop-ivopts : Add live analysis in regs used in decision making X-TM-AS-GCONF: 00 X-Proofpoint-GUID: BEIpf6SfZJsNgDsRedvLIF6yw9t6XKtX X-Proofpoint-ORIG-GUID: 9fAO6CbiCLhnDXJDt4Dq-Dait-c17J1W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-08_03,2023-11-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 phishscore=0 clxscore=1015 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 impostorscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311080123 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782008423087545123 X-GMAIL-MSGID: 1782008423087545123 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. */ +static unsigned +get_regs_used (tree ssa_name) +{ + unsigned regs_used = 0; + gimple *stmt; + use_operand_p use; + basic_block def_bb = NULL; + imm_use_iterator imm_iter; + + stmt = SSA_NAME_DEF_STMT (ssa_name); + if (stmt) + { + def_bb = gimple_bb (stmt); + /* Mark defs in liveout bitmap temporarily. */ + if (def_bb) + regs_used++; + } + else + def_bb = 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 = USE_STMT (use); + basic_block add_block = NULL; + + if (gimple_code (use_stmt) == GIMPLE_PHI) + { + /* Uses in PHI's are considered to be live at exit of the SRC 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 = PHI_ARG_INDEX_FROM_USE (use); + edge e = gimple_phi_arg_edge (as_a (use_stmt), index); + if (e->src != def_bb) + add_block = 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 = gimple_bb (use_stmt); + if (use_bb != def_bb) + add_block = 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 = 0; EXECUTE_IF_SET_IN_BITMAP (data->relevant, 0, j, bi) { struct version_info *info = ver_info (data, j); - if (info->inv_id && info->has_nonlin_use) - n++; + { + tree ssa_name = ssa_name (j); + n = get_regs_used (ssa_name); + if (n >= max) + max = n; + } } - data->regs_used = n; + data->regs_used = max; if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, " regs_used %d\n", n);