From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id DD2BF3848425 for ; Fri, 25 Jun 2021 16:09:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD2BF3848425 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15PG3Ro4109201; Fri, 25 Jun 2021 12:09:27 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 39dh77ba2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Jun 2021 12:09:27 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 15PG9OYC026707; Fri, 25 Jun 2021 16:09:24 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04fra.de.ibm.com with ESMTP id 399878sqwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Jun 2021 16:09:24 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 15PG9LRp14877122 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Jun 2021 16:09:21 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98F8AAE068; Fri, 25 Jun 2021 16:09:21 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4CA01AE071; Fri, 25 Jun 2021 16:09:21 +0000 (GMT) Received: from li-926bd7cc-2dd1-11b2-a85c-f6adc0f5efec.ibm.com (unknown [9.171.46.33]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 25 Jun 2021 16:09:21 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 3/7] ifcvt: Improve costs handling for noce_convert_multiple. Date: Fri, 25 Jun 2021 18:09:01 +0200 Message-Id: <20210625160905.23786-4-rdapp@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210625160905.23786-1-rdapp@linux.ibm.com> References: <20210625160905.23786-1-rdapp@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: nuEFSIWkPZodWoqa0D4X-sIk99jlF46n X-Proofpoint-GUID: nuEFSIWkPZodWoqa0D4X-sIk99jlF46n X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-25_05:2021-06-25, 2021-06-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 adultscore=0 spamscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106250094 X-Spam-Status: No, score=-11.7 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Fri, 25 Jun 2021 16:09:32 -0000 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 initialized the original costs by counting a compare and all the sets inside the then_bb. --- gcc/ifcvt.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 6006055f26a..ac0c142c9fe 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3382,14 +3382,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) { @@ -3425,9 +3428,13 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb) if (!can_conditionally_move_p (GET_MODE (dest))) return false; + potential_cost += pattern_cost (set, 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 @@ -3475,11 +3482,23 @@ 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 compare that we will be needing either way. 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) @@ -3487,6 +3506,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); -- 2.31.1