From patchwork Wed Nov 14 13:07:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 997728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490052-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xt8Ll+Ea"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w4ZQ674hz9s8J for ; Thu, 15 Nov 2018 00:09:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=S7i6wQWvzqsQD34g7ZZEiAz7+hjaey+yS7iJg8kmfkjQi12VnAVeY mH6L5sgyiNqvHnff1NvznTJ1n7qM5+JerxdfP/DtooYXLq1VTfcv13i+ZJnFka3T 3PCqoqg97l721Gw1DQ1sNBIqx2Ozf6ZoAwYN3RTGMUXIjqkDXKBnts= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:in-reply-to:references:message-id; s= default; bh=zomBM/ORNrbJEPkUpzJ4ar8P0as=; b=xt8Ll+EaJxju8dNYSnjl gLjBuSzjIPlxPEjSk6J9Uujy5P2uawDAD/lRr1sjayTsmRpDT5IX6LzjT/KxwkOf /fI4t5B1afqbyMR7g+cyFlqfTQbwbrM4GqMx8K0pSfxDUkAcuH8A8brDDiUeAPGT pVjW+eTUUAUOnQz8DYCpF2g= Received: (qmail 84455 invoked by alias); 14 Nov 2018 13:08:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 84156 invoked by uid 89); 14 Nov 2018 13:08:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Nov 2018 13:08:06 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAED4XPr042670 for ; Wed, 14 Nov 2018 08:08:05 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nrgw42rdt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 14 Nov 2018 08:08:04 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Nov 2018 13:08:03 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 14 Nov 2018 13:08:00 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wAED7xTm4522304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 14 Nov 2018 13:07:59 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 063364C040; Wed, 14 Nov 2018 13:07:59 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3B034C046; Wed, 14 Nov 2018 13:07:58 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.152.222.44]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 14 Nov 2018 13:07:58 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: krebbel@linux.ibm.com, iii@linux.ibm.com Subject: [PATCH 5/6] ifcvt: Only created temporaries as needed. Date: Wed, 14 Nov 2018 14:07:51 +0100 In-Reply-To: <20181114130752.5057-1-rdapp@linux.ibm.com> References: <20181114130752.5057-1-rdapp@linux.ibm.com> x-cbid: 18111413-0016-0000-0000-00000226DBD0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18111413-0017-0000-0000-0000327EF814 Message-Id: <20181114130752.5057-6-rdapp@linux.ibm.com> noce_convert_multiple_sets creates temporaries for the destination of every emitted cmov and expects subsequent passes to get rid of them. This does not happen every time and even if the temporaries are removed, code generation can be affected adversely. In this patch, temporaries are only created if the destination of a set is used in an emitted condition check. --- gcc/ChangeLog: 2018-11-14 Robin Dapp * ifcvt.c (check_need_temps): New function. (noce_convert_multiple_sets): Only created temporaries if needed. --- gcc/ifcvt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 94822c583fe..6d1803ed40d 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -99,6 +99,10 @@ static int dead_or_predicable (basic_block, basic_block, basic_block, edge, int); static void noce_emit_move_insn (rtx, rtx); static rtx_insn *block_has_only_trap (basic_block); +static void check_need_temps (basic_block bb, + hash_map *need_temp, + rtx cond); + /* Count the number of non-jump active insns in BB. */ @@ -3166,6 +3170,12 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) auto_vec unmodified_insns; int count = 0; + hash_map need_temps; + + check_need_temps (then_bb, &need_temps, cond); + + hash_map temps_created; + FOR_BB_INSNS (then_bb, insn) { /* Skip over non-insns. */ @@ -3176,10 +3186,20 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) gcc_checking_assert (set); rtx target = SET_DEST (set); - rtx temp = gen_reg_rtx (GET_MODE (target)); rtx new_val = SET_SRC (set); rtx old_val = target; + rtx dest = SET_DEST (set); + + rtx temp; + if (need_temps.get (dest)) + { + temp = gen_reg_rtx (GET_MODE (target)); + temps_created.put (target, true); + } + else + temp = target; + /* If we were supposed to read from an earlier write in this block, we've changed the register allocation. Rewire the read. While we are looking, also try to catch a swap idiom. */ @@ -3269,8 +3289,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) /* Now fixup the assignments. */ for (int i = 0; i < count; i++) - noce_emit_move_insn (targets[i], temporaries[i]); - + if (temps_created.get(targets[i]) && targets[i] != temporaries[i]) + noce_emit_move_insn (targets[i], temporaries[i]); /* Actually emit the sequence if it isn't too expensive. */ rtx_insn *seq = get_insns (); @@ -3775,6 +3795,34 @@ check_cond_move_block (basic_block bb, return TRUE; } +/* Check for which sets we need to emit temporaries to hold the destination of + a conditional move. */ +static void +check_need_temps (basic_block bb, hash_map *need_temp, rtx cond) +{ + rtx_insn *insn; + + FOR_BB_INSNS (bb, insn) + { + rtx set, dest; + + if (!active_insn_p (insn)) + continue; + + set = single_set (insn); + if (set == NULL_RTX) + continue; + + dest = SET_DEST (set); + + /* noce_emit_cmove will emit the condition check every time it is called + so we need a temp register if the destination is modified. */ + if (reg_overlap_mentioned_p (dest, cond)) + need_temp->put (dest, true); + } +} + + /* Given a basic block BB suitable for conditional move conversion, a condition COND, and pointer maps THEN_VALS and ELSE_VALS containing the register values depending on COND, emit the insns in the block as