From patchwork Mon Dec 6 18:43:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 48548 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4AE123858411 for ; Mon, 6 Dec 2021 18:49:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AE123858411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638816553; bh=uDV9gubH5YjlfcpRfXPDI5FaKDqqrreLvUmoT3wgtB4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JxCu6Pt35dOfhIHmoo6iCRzOY+WKRlneq5BZBtPU9hH4gTiSG/huECGUC+HQYrbAc HrU8pywpdeelrTwcr1hqe7jfP0+uobPRz2NPYROABICvnGelrKC7SYvVEIP+KyzE7z 54qtyZKJt82XMz1K/7SP9/y1N0/nrZMMggt0sx+4= 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 32C073858D28 for ; Mon, 6 Dec 2021 18:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 32C073858D28 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1B6Ho2jj014488; Mon, 6 Dec 2021 18:46:12 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3cspsust7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Dec 2021 18:46:12 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1B6Ih4jd023381; Mon, 6 Dec 2021 18:46:10 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3cqyyafpe1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Dec 2021 18:46:09 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1B6IcR5S29229374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Dec 2021 18:38:27 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5B4E11C052; Mon, 6 Dec 2021 18:46:06 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 51E0811C05B; Mon, 6 Dec 2021 18:46:06 +0000 (GMT) Received: from li-926bd7cc-2dd1-11b2-a85c-f6adc0f5efec.ibm.com (unknown [9.171.69.25]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 6 Dec 2021 18:46:06 +0000 (GMT) To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH v3 3/7] ifcvt: Improve costs handling for noce_convert_multiple. Date: Mon, 6 Dec 2021 19:43:48 +0100 Message-Id: <20211206184352.42264-4-rdapp@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211206184352.42264-1-rdapp@linux.ibm.com> References: <20211206184352.42264-1-rdapp@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JC0469XQdL4WeYhell0J3VxibyCIPskG X-Proofpoint-ORIG-GUID: JC0469XQdL4WeYhell0J3VxibyCIPskG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2021-12-06_07,2021-12-06_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 spamscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112060111 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Robin Dapp via Gcc-patches From: Robin Dapp Reply-To: Robin Dapp Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When noce_convert_multiple is called the original costs are not yet initialized. Therefore, up to now, costs were only ever unfairly compared against COSTS_N_INSNS (2). This would lead to default_noce_conversion_profitable_p () rejecting all but the most contrived of sequences. This patch temporarily initializes the original costs by counting adding costs for all sets inside the then_bb. --- gcc/ifcvt.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 4642176957e..7e1ae2564a3 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3408,14 +3408,17 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) (SET (REG) (REG)) insns suitable for conversion to a series of conditional moves. Also check that we have more than one set (other routines can handle a single set better than we would), and - fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. */ + fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. While going + through the insns store the sum of their potential costs in COST. */ static bool -bb_ok_for_noce_convert_multiple_sets (basic_block test_bb) +bb_ok_for_noce_convert_multiple_sets (basic_block test_bb, unsigned *cost) { rtx_insn *insn; unsigned count = 0; unsigned param = param_max_rtl_if_conversion_insns; + bool speed_p = optimize_bb_for_speed_p (test_bb); + unsigned potential_cost = 0; FOR_BB_INSNS (test_bb, insn) { @@ -3451,9 +3454,13 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb) if (!can_conditionally_move_p (GET_MODE (dest))) return false; + potential_cost += insn_cost (insn, speed_p); + count++; } + *cost += potential_cost; + /* If we would only put out one conditional move, the other strategies this pass tries are better optimized and will be more appropriate. Some targets want to strictly limit the number of conditional moves @@ -3501,11 +3508,24 @@ noce_process_if_block (struct noce_if_info *if_info) to calculate a value for x. ??? For future expansion, further expand the "multiple X" rules. */ - /* First look for multiple SETS. */ + /* First look for multiple SETS. The original costs already include + a base cost of COSTS_N_INSNS (2): one instruction for the compare + (which we will be needing either way) and one instruction for the + branch. When comparing costs we want to use the branch instruction + cost and the sets vs. the cmovs generated here. Therefore subtract + the costs of the compare before checking. + ??? Actually, instead of the branch instruction costs we might want + to use COSTS_N_INSNS (BRANCH_COST ()) as in other places. */ + + unsigned potential_cost = if_info->original_cost - COSTS_N_INSNS (1); + unsigned old_cost = if_info->original_cost; if (!else_bb && HAVE_conditional_move - && bb_ok_for_noce_convert_multiple_sets (then_bb)) + && bb_ok_for_noce_convert_multiple_sets (then_bb, &potential_cost)) { + /* Temporarily set the original costs to what we estimated so + we can determine if the transformation is worth it. */ + if_info->original_cost = potential_cost; if (noce_convert_multiple_sets (if_info)) { if (dump_file && if_info->transform_name) @@ -3513,6 +3533,9 @@ noce_process_if_block (struct noce_if_info *if_info) if_info->transform_name); return TRUE; } + + /* Restore the original costs. */ + if_info->original_cost = old_cost; } bool speed_p = optimize_bb_for_speed_p (test_bb);