From patchwork Mon Dec 6 18:43:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 48553 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 B9F373858434 for ; Mon, 6 Dec 2021 18:54:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9F373858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638816849; bh=pQu7dEX8igQe12bjklQQnavpUdcxGlyPurzD806fGuM=; 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=Lo4OkLi6a9pj9lP3/D8h/lH2U+4aeQAYV7I+XesLnhQnh9Y5l3EGIEEvojJz0JncJ I+4VrIuIfJX2g5UcvqWLJJ4T8XDCEe7ySip3L0ZkWBtmwuL79rMdzsjdvMNrgoidu/ Y3pFuszNcbjb5A3JVXgy3tkpba55zVXTvXPJFYTU= 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 940C23858431 for ; Mon, 6 Dec 2021 18:46:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 940C23858431 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1B6HnvoQ013051; Mon, 6 Dec 2021 18:46:37 GMT 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 3csq7bhb6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Dec 2021 18:46:37 +0000 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 1B6IhlPj008953; Mon, 6 Dec 2021 18:46:34 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04fra.de.ibm.com with ESMTP id 3cqyy9ex1k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Dec 2021 18:46:34 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1B6IkVKT19464592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Dec 2021 18:46:31 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 20A8B11C052; Mon, 6 Dec 2021 18:46:31 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D771A11C050; Mon, 6 Dec 2021 18:46:30 +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:30 +0000 (GMT) To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH v3 7/7] ifcvt: Run second pass if it is possible to omit a temporary. Date: Mon, 6 Dec 2021 19:43:52 +0100 Message-Id: <20211206184352.42264-8-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-ORIG-GUID: XeOsF01lAOQ-B7qVM-F_GDcK6p6MN02n X-Proofpoint-GUID: XeOsF01lAOQ-B7qVM-F_GDcK6p6MN02n 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 spamscore=0 suspectscore=0 adultscore=0 clxscore=1015 mlxlogscore=999 priorityscore=1501 bulkscore=0 mlxscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112060111 X-Spam-Status: No, score=-12.0 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" If one of the to-be-converted SETs requires the original comparison (i.e. in order to generate a min/max insn) but no other insn after it does, we can omit creating temporaries, thus facilitating costing. --- gcc/ifcvt.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index d1e7db1ee27..3be5bb131df 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3262,6 +3262,11 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) need_cmov_or_rewire (then_bb, &need_no_cmov, &rewired_src); + int last_needs_comparison = -1; + bool second_try = false; + +restart: + FOR_BB_INSNS (then_bb, insn) { /* Skip over non-insns. */ @@ -3305,8 +3310,12 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) Therefore we introduce a temporary every time we are about to overwrite a variable used in the check. Costing of a sequence with these is going to be inaccurate so only use temporaries when - needed. */ - if (reg_overlap_mentioned_p (target, cond)) + needed. + + If performing a second try, we know how many insns require a + temporary. For the last of these, we can omit creating one. */ + if (reg_overlap_mentioned_p (target, cond) + && (!second_try || count < last_needs_comparison)) temp = gen_reg_rtx (GET_MODE (target)); else temp = target; @@ -3389,6 +3398,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) { seq = seq1; temp_dest = temp_dest1; + if (!second_try) + last_needs_comparison = count; } else if (seq2 != NULL_RTX) { @@ -3412,6 +3423,24 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) unmodified_insns.safe_push (insn); } + /* If there are insns that overwrite part of the initial + comparison, we can still omit creating temporaries for + the last of them. + As the second try will always create a less expensive, + valid sequence, we do not need to compare and can discard + the first one. */ + if (!second_try && last_needs_comparison >= 0) + { + end_sequence (); + start_sequence (); + count = 0; + targets.truncate (0); + temporaries.truncate (0); + unmodified_insns.truncate (0); + second_try = true; + goto restart; + } + /* We must have seen some sort of insn to insert, otherwise we were given an empty BB to convert, and we can't handle that. */ gcc_assert (!unmodified_insns.is_empty ());