From patchwork Fri Aug 2 15:10:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141257 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-506111-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="Ifzx0/6h"; 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 460Vwl4k7pz9s7T for ; Sat, 3 Aug 2019 01:11:03 +1000 (AEST) 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=D6thNGwiovfa7fHE1yWLcyvuaHOEyHFRkl8LiC3RBNZdssDIP/lw2 fms1ZDYUU1THVMjvTwGh41uwyN4Hz7IHGjrIwADrozvxoV0hAWBKQ2wCyPFPTSHh Q209z81a0Pv+akMSciuIvxgwI/By6mVCxMMEuA0PmTrne2zuF7cTl0= 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=botl56BLjHvcVC5ziA9+ahOI74s=; b=Ifzx0/6hhr39bvkQ3l+h P9N4aRCLa+aKgkuXjuV77q87mh/8kiAWNwN0A1GNLHdptRySfDczXuR3EXW3XQ1T E4458bLF65mSBnQREdnaCfhf+QoT3qb+0U9xLSEB+q600ZWL20Sm6KhFZunLTgb2 WRlsv+ta8WJ33XxjSujZLIs= Received: (qmail 1516 invoked by alias); 2 Aug 2019 15:10:43 -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 1493 invoked by uid 89); 2 Aug 2019 15:10:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 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.1 spammy=1086 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; Fri, 02 Aug 2019 15:10:42 +0000 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F7kge182890 for ; Fri, 2 Aug 2019 11:10:40 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2u4nckp219-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:40 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:37 +0100 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) 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) Fri, 2 Aug 2019 16:10:35 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72FAY8N41288114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:34 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F1C4F11C04A; Fri, 2 Aug 2019 15:10:33 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A707611C050; Fri, 2 Aug 2019 15:10:33 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:33 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 1/9] ifcvt: Store the number of created cmovs. Date: Fri, 2 Aug 2019 17:10:20 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0016-0000-0000-00000299178D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0017-0000-0000-000032F8182F Message-Id: <20190802151028.15590-2-rdapp@linux.ibm.com> X-IsSubscribed: yes This patch saves the number of created conditional moves by noce_convert_multiple_sets in the IF_INFO struct. This may be used by the backend to easier decide whether to accept a generated sequence or not. --- gcc/ifcvt.c | 10 ++++++++-- gcc/ifcvt.h | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index e0c9522057a..b80dbc43d83 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3247,9 +3247,14 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) /* Actually emit the sequence if it isn't too expensive. */ rtx_insn *seq = get_insns (); + if_info->transform_name = "noce_convert_multiple_sets"; + if_info->created_cmovs = count; + if (!targetm.noce_conversion_profitable_p (seq, if_info)) { end_sequence (); + if_info->transform_name = ""; + if_info->created_cmovs = 0; return FALSE; } @@ -3296,7 +3301,7 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) } num_updated_if_blocks++; - if_info->transform_name = "noce_convert_multiple_sets"; + return TRUE; } @@ -4060,7 +4065,8 @@ noce_find_if_block (basic_block test_bb, edge then_edge, edge else_edge, and jump_insns are always given a cost of 1 by seq_cost, so treat both instructions as having cost COSTS_N_INSNS (1). */ if_info.original_cost = COSTS_N_INSNS (2); - + if_info.transform_name = ""; + if_info.created_cmovs = 0; /* Do the real work. */ diff --git a/gcc/ifcvt.h b/gcc/ifcvt.h index 153ad961b2c..130559c0911 100644 --- a/gcc/ifcvt.h +++ b/gcc/ifcvt.h @@ -108,6 +108,10 @@ struct noce_if_info /* The name of the noce transform that succeeded in if-converting this structure. Used for debugging. */ const char *transform_name; + + /* The number of created conditional moves in case we convert multiple + sets. */ + unsigned int created_cmovs; }; #endif /* GCC_IFCVT_H */ From patchwork Fri Aug 2 15:10:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141255 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-506110-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="sMWecghf"; 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 460VwZ2vpDz9s7T for ; Sat, 3 Aug 2019 01:10:51 +1000 (AEST) 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=m/wrwGXGp0hJV1Dubpf3hQx1Pe6U6UfFDpL7oQfdM4oTYvP139WCz tyXSyeK1ChWBrEmCe5a7+/EwEy9EqDyUxqQqEyDwSjwhJ51kVhezBd4oaVhoJQz6 jbxE82tp0k/uOjQJe8hzjEv79wSWgr9dHSDsPN+oQjh8g0m8fDB/cQ= 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=PQekeD9/JsP68ZseNyy0WQ8xMuA=; b=sMWecghfhgvg4w4hBiP5 T9lGHYREC/ZZ0pPiQlCCkXdvMTJYHZbIecOwVMJIyuGpCPfEbtx58gzzxTGr9VDG Mbz92v6O1DPE+ta1izsQZDoBPDpnQNm3Fec2gU52N6Py8O393DaahXtJRSIivAl1 J1fsPqvewQ/xXHhxJNg4WkI= Received: (qmail 1505 invoked by alias); 2 Aug 2019 15:10:43 -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 1482 invoked by uid 89); 2 Aug 2019 15:10:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.0 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.1 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 15:10:41 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F7f6S141939 for ; Fri, 2 Aug 2019 11:10:40 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4p13m3cs-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:39 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:37 +0100 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 2 Aug 2019 16:10:35 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72FAYHI42139918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:34 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6989811C054; Fri, 2 Aug 2019 15:10:34 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1519B11C050; Fri, 2 Aug 2019 15:10:34 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:33 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 2/9] ifcvt: Use enum instead of transform_name string. Date: Fri, 2 Aug 2019 17:10:21 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0028-0000-0000-0000038A8049 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0029-0000-0000-0000244AD8C9 Message-Id: <20190802151028.15590-3-rdapp@linux.ibm.com> X-IsSubscribed: yes This patch introduces an enum for ifcvt's various noce transformations. As the transformation might be queried by the backend, I find it nicer to allow checking for a proper type instead of a string comparison. --- gcc/ifcvt.c | 46 ++++++++++++++++++------------------ gcc/ifcvt.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 25 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index b80dbc43d83..e95ff9ee9b0 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -1105,7 +1105,7 @@ noce_try_move (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); } - if_info->transform_name = "noce_try_move"; + if_info->transform = ifcvt_transform_noce_try_move; return TRUE; } return FALSE; @@ -1139,7 +1139,7 @@ noce_try_ifelse_collapse (struct noce_if_info * if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_ifelse_collapse"; + if_info->transform = ifcvt_transform_noce_try_ifelse_collapse; return TRUE; } @@ -1186,7 +1186,7 @@ noce_try_store_flag (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_store_flag"; + if_info->transform = ifcvt_transform_noce_try_store_flag; return TRUE; } else @@ -1265,7 +1265,7 @@ noce_try_inverse_constants (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_inverse_constants"; + if_info->transform = ifcvt_transform_noce_try_inverse_constants; return true; } @@ -1485,7 +1485,7 @@ noce_try_store_flag_constants (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_store_flag_constants"; + if_info->transform = ifcvt_transform_noce_try_store_flag_constants; return TRUE; } @@ -1546,7 +1546,7 @@ noce_try_addcc (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_addcc"; + if_info->transform = ifcvt_transform_noce_try_addcc; return TRUE; } @@ -1588,7 +1588,7 @@ noce_try_addcc (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_addcc"; + if_info->transform = ifcvt_transform_noce_try_addcc; return TRUE; } end_sequence (); @@ -1639,7 +1639,7 @@ noce_try_store_flag_mask (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_store_flag_mask"; + if_info->transform = ifcvt_transform_noce_try_store_flag_mask; return TRUE; } @@ -1791,7 +1791,7 @@ noce_try_cmove (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_cmove"; + if_info->transform = ifcvt_transform_noce_try_cmove; return TRUE; } @@ -1844,7 +1844,7 @@ noce_try_cmove (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_cmove"; + if_info->transform = ifcvt_transform_noce_try_cmove; return TRUE; } else @@ -2286,7 +2286,7 @@ noce_try_cmove_arith (struct noce_if_info *if_info) emit_insn_before_setloc (ifcvt_seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_cmove_arith"; + if_info->transform = ifcvt_transform_noce_try_cmove_arith; return TRUE; end_seq_and_fail: @@ -2544,7 +2544,7 @@ noce_try_minmax (struct noce_if_info *if_info) if_info->cond = cond; if_info->cond_earliest = earliest; if_info->rev_cond = NULL_RTX; - if_info->transform_name = "noce_try_minmax"; + if_info->transform = ifcvt_transform_noce_try_minmax; return TRUE; } @@ -2712,7 +2712,7 @@ noce_try_abs (struct noce_if_info *if_info) if_info->cond = cond; if_info->cond_earliest = earliest; if_info->rev_cond = NULL_RTX; - if_info->transform_name = "noce_try_abs"; + if_info->transform = ifcvt_transform_noce_try_abs; return TRUE; } @@ -2794,7 +2794,7 @@ noce_try_sign_mask (struct noce_if_info *if_info) return FALSE; emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); - if_info->transform_name = "noce_try_sign_mask"; + if_info->transform = ifcvt_transform_noce_try_sign_mask; return TRUE; } @@ -2904,7 +2904,7 @@ noce_try_bitop (struct noce_if_info *if_info) emit_insn_before_setloc (seq, if_info->jump, INSN_LOCATION (if_info->insn_a)); } - if_info->transform_name = "noce_try_bitop"; + if_info->transform = ifcvt_transform_noce_try_bitop; return TRUE; } @@ -3244,16 +3244,17 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) for (int i = 0; i < count; i++) noce_emit_move_insn (targets[i], temporaries[i]); + /* Actually emit the sequence if it isn't too expensive. */ rtx_insn *seq = get_insns (); - if_info->transform_name = "noce_convert_multiple_sets"; + if_info->transform = ifcvt_transform_noce_convert_multiple_sets; if_info->created_cmovs = count; if (!targetm.noce_conversion_profitable_p (seq, if_info)) { end_sequence (); - if_info->transform_name = ""; + if_info->transform = ifcvt_transform_none; if_info->created_cmovs = 0; return FALSE; } @@ -3400,15 +3401,16 @@ noce_process_if_block (struct noce_if_info *if_info) { if (noce_convert_multiple_sets (if_info)) { - if (dump_file && if_info->transform_name) + if (dump_file && if_info->transform) fprintf (dump_file, "if-conversion succeeded through %s\n", - if_info->transform_name); + ifcvt_get_transform_name (if_info->transform)); return TRUE; } } bool speed_p = optimize_bb_for_speed_p (test_bb); unsigned int then_cost = 0, else_cost = 0; + if (!bb_valid_for_noce_process_p (then_bb, cond, &then_cost, &if_info->then_simple)) return false; @@ -3619,9 +3621,9 @@ noce_process_if_block (struct noce_if_info *if_info) return FALSE; success: - if (dump_file && if_info->transform_name) + if (dump_file && if_info->transform) fprintf (dump_file, "if-conversion succeeded through %s\n", - if_info->transform_name); + ifcvt_get_transform_name (if_info->transform)); /* If we used a temporary, fix it up now. */ if (orig_x != x) @@ -4065,7 +4067,7 @@ noce_find_if_block (basic_block test_bb, edge then_edge, edge else_edge, and jump_insns are always given a cost of 1 by seq_cost, so treat both instructions as having cost COSTS_N_INSNS (1). */ if_info.original_cost = COSTS_N_INSNS (2); - if_info.transform_name = ""; + if_info.transform = ifcvt_transform_none; if_info.created_cmovs = 0; /* Do the real work. */ diff --git a/gcc/ifcvt.h b/gcc/ifcvt.h index 130559c0911..3776a25c3f6 100644 --- a/gcc/ifcvt.h +++ b/gcc/ifcvt.h @@ -40,6 +40,66 @@ struct ce_if_block int pass; /* Pass number. */ }; +enum ifcvt_transform +{ + ifcvt_transform_none = 0, + ifcvt_transform_noce_try_move, + ifcvt_transform_noce_try_ifelse_collapse, + ifcvt_transform_noce_try_store_flag, + ifcvt_transform_noce_try_inverse_constants, + ifcvt_transform_noce_try_store_flag_constants, + ifcvt_transform_noce_try_addcc, + ifcvt_transform_noce_try_store_flag_mask, + ifcvt_transform_noce_try_cmove, + ifcvt_transform_noce_try_cmove_arith, + ifcvt_transform_noce_try_minmax, + ifcvt_transform_noce_try_abs, + ifcvt_transform_noce_try_sign_mask, + ifcvt_transform_noce_try_bitop, + ifcvt_transform_noce_convert_multiple_sets +}; + +inline const char * +ifcvt_get_transform_name (enum ifcvt_transform transform) +{ + switch (transform) + { + case ifcvt_transform_none: + return ""; + case ifcvt_transform_noce_try_move: + return "noce_try_move"; + case ifcvt_transform_noce_try_ifelse_collapse: + return "noce_try_ifelse_collapse"; + case ifcvt_transform_noce_try_store_flag: + return "noce_try_store_flag"; + case ifcvt_transform_noce_try_inverse_constants: + return "noce_try_inverse_constants"; + case ifcvt_transform_noce_try_store_flag_constants: + return "noce_try_store_flag_constants"; + case ifcvt_transform_noce_try_addcc: + return "noce_try_addcc"; + case ifcvt_transform_noce_try_store_flag_mask: + return "noce_try_store_flag_mask"; + case ifcvt_transform_noce_try_cmove: + return "noce_try_cmove"; + case ifcvt_transform_noce_try_cmove_arith: + return "noce_try_cmove_arith"; + case ifcvt_transform_noce_try_minmax: + return "noce_try_minmax"; + case ifcvt_transform_noce_try_abs: + return "noce_try_abs"; + case ifcvt_transform_noce_try_sign_mask: + return "noce_try_sign_mask"; + case ifcvt_transform_noce_try_bitop: + return "noce_try_bitop"; + case ifcvt_transform_noce_convert_multiple_sets: + return "noce_convert_multiple_sets"; + default: + return "unknown transform"; + } +} + + /* Used by noce_process_if_block to communicate with its subroutines. The subroutines know that A and B may be evaluated freely. They @@ -105,9 +165,10 @@ struct noce_if_info generate to replace this branch. */ unsigned int max_seq_cost; - /* The name of the noce transform that succeeded in if-converting - this structure. Used for debugging. */ - const char *transform_name; + /* The noce transform that succeeded in if-converting this structure. + Used for letting the backend determine which transform succeeded + and for debugging output. */ + enum ifcvt_transform transform; /* The number of created conditional moves in case we convert multiple sets. */ From patchwork Fri Aug 2 15:10:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141259 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-506113-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="yYdJn9Fl"; 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 460VxB01vdz9sBF for ; Sat, 3 Aug 2019 01:11:25 +1000 (AEST) 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=ncuJRb5dOE+f5lfcxotaza6LbXEJxuRJ7W6UGw2YEdaOqQ+6DgHOG fMpIRn8dAelx/ZcfndxBXjxZ1HBem4THrvKUBCSCk5JRJ21xKDlLZ9NsAd+DnccT MUgO7XgYtB1L5TcXehfBVXG5qAQT6yIkpF9iEffY3YcZ89+l6TA40o= 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=xqKFhO8M3YJhRfyd68y6iBl+SR0=; b=yYdJn9FlUAsMpnuQzdG1 fZyJ61Bak8i81EvlTklXjClrrtmr3jfbC7MZxKYpYYzKx4olgpjqHoUUQc2ZU1PQ ZgWkZrMxiV1kyW5n3/mp+yTFFp2sQnuj7DWAHAVvYsL3BytppfY06vwteo1pl9NZ BS1xxXXH3hkyygOu5gNj/So= Received: (qmail 1606 invoked by alias); 2 Aug 2019 15:10:44 -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 1512 invoked by uid 89); 2 Aug 2019 15:10:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 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.1 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; Fri, 02 Aug 2019 15:10:42 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F7bEQ004299 for ; Fri, 2 Aug 2019 11:10:40 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2u4nqd59tv-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:40 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:38 +0100 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 2 Aug 2019 16:10:36 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72FAYSo12517758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:34 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB2D011C058; Fri, 2 Aug 2019 15:10:34 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8135C11C050; Fri, 2 Aug 2019 15:10:34 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:34 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 3/9] ifcvt: Only created temporaries as needed. Date: Fri, 2 Aug 2019 17:10:22 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0012-0000-0000-00000338DDA7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0013-0000-0000-000021728EA6 Message-Id: <20190802151028.15590-4-rdapp@linux.ibm.com> X-IsSubscribed: yes 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/ifcvt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index e95ff9ee9b0..253b8a96c1a 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. */ @@ -3145,6 +3149,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. */ @@ -3155,10 +3165,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. */ @@ -3242,8 +3262,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 (); @@ -3749,6 +3769,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 From patchwork Fri Aug 2 15:10:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141260 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-506114-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="cYpih9NA"; 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 460VxP1DQ6z9sBF for ; Sat, 3 Aug 2019 01:11:36 +1000 (AEST) 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=OITf/UVsYe7u67Aqdc3QLv58etW+RPeyRDUwz4wKat6DEqdkqk2m8 dfo3VYvs72qMYb7+XLWyXa2ydzBwAscbs89kr02SJeDZ5LUe79OWMLf/aKGRekNP jsEJ/StI2LJgjLppDar6tSvygfJtfUEOHg6v+s5GVsYuWyjCwNO9ZI= 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=EPHnk6padYfUCNJYwRsT5CPD5TA=; b=cYpih9NApdpB1WqzVWIG A5MwwPF0tuL1NsFx2LMWxc5s2LmExw/DaWfpVfG0ziZHuIcSpsiNfK3+GQNwpEpW GoCuBtEIsdNN6x9zv3k1XAFLYT9xo8c1XdvyabG1IGFrtZcyZ/BDXXY0SWRM0q29 5F8JHiCGtjGnpIuiqMB1mhk= Received: (qmail 1996 invoked by alias); 2 Aug 2019 15:10:46 -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 1931 invoked by uid 89); 2 Aug 2019 15:10:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.3 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.1 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 15:10:44 +0000 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F6eHe006533 for ; Fri, 2 Aug 2019 11:10:42 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4p2bmds6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:42 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:39 +0100 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 2 Aug 2019 16:10:37 +0100 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 x72FAI3i39452964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:18 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38AE611C052; Fri, 2 Aug 2019 15:10:35 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E2A3411C05B; Fri, 2 Aug 2019 15:10:34 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:34 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 4/9] ifcvt: Estimate original costs before convert_multiple. Date: Fri, 2 Aug 2019 17:10:23 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-4275-0000-0000-0000035344B4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-4276-0000-0000-000038643ABF Message-Id: <20190802151028.15590-5-rdapp@linux.ibm.com> X-IsSubscribed: yes This patch extends bb_ok_for_noce_convert_multiple_sets by a temporary cost estimation that can be used by noce_convert_multiple_sets. --- gcc/ifcvt.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 253b8a96c1a..55205cac153 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3333,11 +3333,13 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. */ 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_VALUE (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) { @@ -3373,9 +3375,14 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb) if (!can_conditionally_move_p (GET_MODE (dest))) return false; + rtx sset = single_set (insn); + potential_cost += pattern_cost (sset, 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 @@ -3414,11 +3421,15 @@ noce_process_if_block (struct noce_if_info *if_info) ??? For future expansion, further expand the "multiple X" rules. */ /* First look for multiple SETS. */ + unsigned int mcost = if_info->original_cost; + unsigned tmp_cost = if_info->original_cost; if (!else_bb && HAVE_conditional_move && !HAVE_cc0 - && bb_ok_for_noce_convert_multiple_sets (then_bb)) + && bb_ok_for_noce_convert_multiple_sets (then_bb, &mcost)) { + /* Temporarily set the original costs to what we estimated. */ + if_info->original_cost = mcost; if (noce_convert_multiple_sets (if_info)) { if (dump_file && if_info->transform) @@ -3427,6 +3438,8 @@ noce_process_if_block (struct noce_if_info *if_info) return TRUE; } } + /* Restore the original costs. */ + if_info->original_cost = tmp_cost; bool speed_p = optimize_bb_for_speed_p (test_bb); unsigned int then_cost = 0, else_cost = 0; From patchwork Fri Aug 2 15:10:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141266 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-506119-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="xqLVdjSj"; 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 460Vyg5rmjz9sBF for ; Sat, 3 Aug 2019 01:12:43 +1000 (AEST) 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=VdlRQRIr+8OT8Ttv9O3Nhoso9fIcsd1uMiNg+u55hoAPL/gxyKYVd hq64O1ek+BvRkKxFKBzzp7zNsfrTZkkSU4HszNM+Zx52ZkGzkAN4H4TLWn+MfENB 09/lOxA+j+J8KbAzB6eRJ17tf0eImRFU9kHtMbd6etsmvOsLpSbqKU= 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=b3t0p7+T71IFDXoHDtHm7BxtOXM=; b=xqLVdjSjcDr3fogXgaPu Kg9McqHoZi0fq2u0+KyKB0fEdcG2jxpel0iHH+qLsJw6IRQULYqO7/opfPwjQ/Kn xIhdgD+V51djMBdMD4S5TkvHZAZEvqS+V/ZTanYOj/VyqfhqW7nP3Ao+d6qz5WV9 37Wdwap30l2maWpA5CZKPy4= Received: (qmail 2846 invoked by alias); 2 Aug 2019 15:10:50 -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 2783 invoked by uid 89); 2 Aug 2019 15:10:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_SOFTFAIL autolearn=ham version=3.3.1 spammy= X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 15:10:48 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZCf-0001Ee-NF for gcc-patches@gcc.gnu.org; Fri, 02 Aug 2019 11:10:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:18706 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZCf-0001At-HR for gcc-patches@gcc.gnu.org; Fri, 02 Aug 2019 11:10:45 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F8OLD062431 for ; Fri, 2 Aug 2019 11:10:42 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 2u4p3euth5-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:41 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:39 +0100 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 2 Aug 2019 16:10:37 +0100 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 x72FAIaW12976384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:18 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D66011C054; Fri, 2 Aug 2019 15:10:35 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 500A711C050; Fri, 2 Aug 2019 15:10:35 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:35 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 5/9] ifcvt: Allow constants operands in noce_convert_multiple_sets. Date: Fri, 2 Aug 2019 17:10:24 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0008-0000-0000-000003041739 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0009-0000-0000-0000A17E17A7 Message-Id: <20190802151028.15590-6-rdapp@linux.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 X-IsSubscribed: yes This patch checks allows immediate then/else operands for cmovs. We rely on,emit_conditional_move returning NULL if something unsupported was generated. Also, minor refactoring is performed. --- gcc/ChangeLog: 2018-11-14 Robin Dapp * ifcvt.c (have_const_cmov): New function. (noce_convert_multiple_sets): Allow constants if supported. (bb_ok_for_noce_convert_multiple_sets): Likewise. (check_cond_move_block): Refactor. --- gcc/ifcvt.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 55205cac153..99716e5f63c 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3214,7 +3214,9 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) we'll end up trying to emit r4:HI = cond ? (r1:SI) : (r3:HI). Wrap the two cmove operands into subregs if appropriate to prevent that. */ - if (GET_MODE (new_val) != GET_MODE (temp)) + + if (!CONST_INT_P (new_val) + && GET_MODE (new_val) != GET_MODE (temp)) { machine_mode src_mode = GET_MODE (new_val); machine_mode dst_mode = GET_MODE (temp); @@ -3225,7 +3227,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) } new_val = lowpart_subreg (dst_mode, new_val, src_mode); } - if (GET_MODE (old_val) != GET_MODE (temp)) + if (!CONST_INT_P (old_val) + && GET_MODE (old_val) != GET_MODE (temp)) { machine_mode src_mode = GET_MODE (old_val); machine_mode dst_mode = GET_MODE (temp); @@ -3362,9 +3365,9 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb, unsigned *cost) if (!REG_P (dest)) return false; - if (!(REG_P (src) - || (GET_CODE (src) == SUBREG && REG_P (SUBREG_REG (src)) - && subreg_lowpart_p (src)))) + if (!((REG_P (src) || (CONST_INT_P (src))) + || (GET_CODE (src) == SUBREG && REG_P (SUBREG_REG (src)) + && subreg_lowpart_p (src)))) return false; /* Destination must be appropriate for a conditional write. */ @@ -3724,7 +3727,7 @@ check_cond_move_block (basic_block bb, { rtx set, dest, src; - if (!NONDEBUG_INSN_P (insn) || JUMP_P (insn)) + if (!active_insn_p (insn)) continue; set = single_set (insn); if (!set) @@ -3740,10 +3743,8 @@ check_cond_move_block (basic_block bb, if (!CONSTANT_P (src) && !register_operand (src, VOIDmode)) return FALSE; - if (side_effects_p (src) || side_effects_p (dest)) - return FALSE; - - if (may_trap_p (src) || may_trap_p (dest)) + /* Check for side effects and trapping. */ + if (!noce_operand_ok (src) || !noce_operand_ok (dest)) return FALSE; /* Don't try to handle this if the source register was From patchwork Fri Aug 2 15:10:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141261 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-506115-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="FsUC3h7Y"; 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 460Vxf188kz9sBF for ; Sat, 3 Aug 2019 01:11:48 +1000 (AEST) 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=QuWIA2uJ5y+ysL0bVF8kKIdgt3faA2EWWwipRnEnAa/pMM4rbvFZT 85OEJeovJZUnU1DsOvBoqNNCcfkA9JM4jFLW0rfZJ13Wh9Yiy7bGtxt0XHctyT7M 3W0XBTm6fBWYXxjUytP0UNZMGZEwFcg50Wrsf5EAVrUPwxmIP71iYQ= 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=TDuWZhA7tvxYJbDqcBJj6AwWgwk=; b=FsUC3h7YkZzr9muLn2Bs crm+z2dPJnolZlzfszgFu6EE1Vp8z9hnpePZ7WjM5MF8coRy+94iSc2eYgGm61Lk s9SRf6DoJsthPAf5zfqiG4L87pU9LiT0dTzXwByyv67oJ28wfDEYXFMUa9Uf3Jz3 8NtzDyJdyGX268wreToD2Kc= Received: (qmail 2016 invoked by alias); 2 Aug 2019 15:10:46 -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 1953 invoked by uid 89); 2 Aug 2019 15:10:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.6 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.1 spammy=complement X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 15:10:43 +0000 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F6brF126073 for ; Fri, 2 Aug 2019 11:10:41 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4pjqk0v2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:40 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:38 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 2 Aug 2019 16:10:37 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72FAanv46137526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:36 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A28D11C064; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B465A11C050; Fri, 2 Aug 2019 15:10:35 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:35 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 6/9] ifcvt: Extract cc comparison from jump. Date: Fri, 2 Aug 2019 17:10:25 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0020-0000-0000-00000359D48B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0021-0000-0000-000021ADE967 Message-Id: <20190802151028.15590-7-rdapp@linux.ibm.com> X-IsSubscribed: yes This patch extracts a cc comparison from the initial compare/jump insn and allows it to be passed to noce_emit_cmove and emit_conditional_move. --- gcc/ifcvt.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++---- gcc/optabs.c | 7 ++++-- gcc/optabs.h | 2 +- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 99716e5f63c..3db707e1fd1 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -86,6 +86,7 @@ static rtx_insn *find_active_insn_after (basic_block, rtx_insn *); static basic_block block_fallthru (basic_block); static rtx cond_exec_get_condition (rtx_insn *); static rtx noce_get_condition (rtx_insn *, rtx_insn **, bool); +static rtx noce_get_compare (rtx_insn *, bool); static int noce_operand_ok (const_rtx); static void merge_if_block (ce_if_block *); static int find_cond_trap (basic_block, edge, edge); @@ -775,7 +776,7 @@ static int noce_try_addcc (struct noce_if_info *); static int noce_try_store_flag_constants (struct noce_if_info *); static int noce_try_store_flag_mask (struct noce_if_info *); static rtx noce_emit_cmove (struct noce_if_info *, rtx, enum rtx_code, rtx, - rtx, rtx, rtx); + rtx, rtx, rtx, rtx = NULL); static int noce_try_cmove (struct noce_if_info *); static int noce_try_cmove_arith (struct noce_if_info *); static rtx noce_get_alt_condition (struct noce_if_info *, rtx, rtx_insn **); @@ -1658,7 +1659,7 @@ noce_try_store_flag_mask (struct noce_if_info *if_info) static rtx noce_emit_cmove (struct noce_if_info *if_info, rtx x, enum rtx_code code, - rtx cmp_a, rtx cmp_b, rtx vfalse, rtx vtrue) + rtx cmp_a, rtx cmp_b, rtx vfalse, rtx vtrue, rtx cc_cmp) { rtx target ATTRIBUTE_UNUSED; int unsignedp ATTRIBUTE_UNUSED; @@ -1706,7 +1707,7 @@ noce_emit_cmove (struct noce_if_info *if_info, rtx x, enum rtx_code code, target = emit_conditional_move (x, code, cmp_a, cmp_b, VOIDmode, vtrue, vfalse, GET_MODE (x), - unsignedp); + unsignedp, cc_cmp); if (target) return target; @@ -2970,6 +2971,60 @@ noce_get_condition (rtx_insn *jump, rtx_insn **earliest, bool then_else_reversed return tmp; } +/* Get the comparison from the insn. */ +static rtx +noce_get_compare (rtx_insn *jump, bool then_else_reversed) +{ + enum rtx_code code; + const_rtx set; + rtx tem; + rtx op0, op1; + + if (!have_cbranchcc4) + return 0; + + if (! any_condjump_p (jump)) + return NULL_RTX; + + set = pc_set (jump); + + /* If this branches to JUMP_LABEL when the condition is false, + reverse the condition. */ + bool reverse = (GET_CODE (XEXP (SET_SRC (set), 2)) == LABEL_REF + && label_ref_label (XEXP (SET_SRC (set), 2)) == JUMP_LABEL (jump)); + + /* We may have to reverse because the caller's if block is not canonical, + i.e. the THEN block isn't the fallthrough block for the TEST block + (see find_if_header). */ + if (then_else_reversed) + reverse = !reverse; + + rtx cond = XEXP (SET_SRC (set), 0); + + code = GET_CODE (cond); + op0 = XEXP (cond, 0); + op1 = XEXP (cond, 1); + + if (reverse) + code = reversed_comparison_code (cond, jump); + if (code == UNKNOWN) + return 0; + + /* If constant is first, put it last. */ + if (CONSTANT_P (op0)) + code = swap_condition (code), tem = op0, op0 = op1, op1 = tem; + + /* Never return CC0; return zero instead. */ + if (CC0_P (op0)) + return 0; + + /* We promised to return a comparison. */ + rtx ret = gen_rtx_fmt_ee (code, VOIDmode, op0, op1); + if (COMPARISON_P (ret)) + return ret; + return 0; +} + /* Return true if OP is ok for if-then-else processing. */ static int @@ -3140,6 +3195,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) rtx y = XEXP (cond, 1); rtx_code cond_code = GET_CODE (cond); + rtx cc_cmp = noce_get_compare (jump, false); + /* The true targets for a conditional move. */ auto_vec targets; /* The temporaries introduced to allow us to not consider register @@ -3151,7 +3208,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) hash_map need_temps; - check_need_temps (then_bb, &need_temps, cond); + if (!cc_cmp) + check_need_temps (then_bb, &need_temps, cond); hash_map temps_created; @@ -3242,7 +3300,7 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) /* Actually emit the conditional move. */ rtx temp_dest = noce_emit_cmove (if_info, temp, cond_code, - x, y, new_val, old_val); + x, y, new_val, old_val, cc_cmp); /* If we failed to expand the conditional move, drop out and don't try to continue. */ diff --git a/gcc/optabs.c b/gcc/optabs.c index 06bcaab1f55..3ce6f8cdd30 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -4325,7 +4325,7 @@ emit_indirect_jump (rtx loc) rtx emit_conditional_move (rtx target, enum rtx_code code, rtx op0, rtx op1, machine_mode cmode, rtx op2, rtx op3, - machine_mode mode, int unsignedp) + machine_mode mode, int unsignedp, rtx cc_cmp) { rtx comparison; rtx_insn *last; @@ -4408,7 +4408,10 @@ emit_conditional_move (rtx target, enum rtx_code code, rtx op0, rtx op1, class expand_operand ops[4]; create_output_operand (&ops[0], target, mode); - create_fixed_operand (&ops[1], comparison); + if (cc_cmp) + create_fixed_operand (&ops[1], cc_cmp); + else + create_fixed_operand (&ops[1], comparison); create_input_operand (&ops[2], op2, mode); create_input_operand (&ops[3], op3, mode); if (maybe_expand_insn (icode, 4, ops)) diff --git a/gcc/optabs.h b/gcc/optabs.h index 0654107d6e3..c4540f87144 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -258,7 +258,7 @@ extern void emit_indirect_jump (rtx); /* Emit a conditional move operation. */ rtx emit_conditional_move (rtx, enum rtx_code, rtx, rtx, machine_mode, - rtx, rtx, machine_mode, int); + rtx, rtx, machine_mode, int, rtx = NULL); /* Emit a conditional negate or bitwise complement operation. */ rtx emit_conditional_neg_or_complement (rtx, rtx_code, machine_mode, rtx, From patchwork Fri Aug 2 15:10:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141262 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-506116-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="CiZ/0X1X"; 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 460Vxw4Bw1z9sBF for ; Sat, 3 Aug 2019 01:12:04 +1000 (AEST) 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=CSSgeJwOnaSC866Nn8d8VdqmKPtj/u6uXpC/Wk7SAVnKX0DoWdnf8 UFrnmTkdFOcq6WVwW+Z22KnmkgtOotfRss51LFVHMZTqCdyFt10PfsXKfOYO0ydI OpzAkQ+pVRtWqKt06Ob4DpMM10HUnKusCh83bIokE6AiK1Wfz3rzUQ= 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=xsm4zj0Z08TTueKhzfu1JRb3JD8=; b=CiZ/0X1X5ujmU3GewiRB dv1EMOl7o1DQ22/leHHs1OLxcoOI0t9wz6Ast7EQudeOlptwKOzhU9au0rv+ZH2g xEltloOK2CRmHMEI2/SH64tXYbwZ2oed3jtTpXT/svJhkBGLvON/pyb6s1xsavuz 8YHCn2/C0PQvIn7VQ2CnCLQ= Received: (qmail 2149 invoked by alias); 2 Aug 2019 15:10:46 -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 2018 invoked by uid 89); 2 Aug 2019 15:10:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.7 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.1 spammy=inaccurate X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 15:10:44 +0000 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F757K081855 for ; Fri, 2 Aug 2019 11:10:42 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4n03fbyj-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:42 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:40 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) 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) Fri, 2 Aug 2019 16:10:38 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72FAa6533751152 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:36 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A94211C064; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21A2611C050; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 7/9] ifcvt: Emit two cmov variants and choose the less expensive one. Date: Fri, 2 Aug 2019 17:10:26 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0016-0000-0000-00000299178F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0017-0000-0000-000032F81830 Message-Id: <20190802151028.15590-8-rdapp@linux.ibm.com> X-IsSubscribed: yes This patch duplicates the previous noce_emit_cmove logic. First it passes the canonical comparison emits the sequence and costs it. Then, a second, separate sequence is created by passing the cc compare we extracted before. The costs of both sequences are compared and the cheaper one is emitted. --- gcc/ifcvt.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 9 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 3db707e1fd1..955f9541f60 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3208,8 +3208,11 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) hash_map need_temps; - if (!cc_cmp) - check_need_temps (then_bb, &need_temps, cond); + /* If we newly set a CC before a cmov, we might need a temporary + even though the compare will be removed by a later pass. Costing + of a sequence with these will be inaccurate. */ + + check_need_temps (then_bb, &need_temps, cond); hash_map temps_created; @@ -3298,18 +3301,103 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) old_val = lowpart_subreg (dst_mode, old_val, src_mode); } - /* Actually emit the conditional move. */ - rtx temp_dest = noce_emit_cmove (if_info, temp, cond_code, - x, y, new_val, old_val, cc_cmp); + /* Try emitting a conditional move passing the backend the + canonicalized comparison. This can e.g. be used to recognize + expressions like + + if (a < b) + { + ... + b = a; + } + + A backend can recognize this and emit a min/max insn. + We will still emit a superfluous CC comparison before the + min/max, though, which complicates costing. + */ + + rtx_insn *seq, *seq1 = 0, *seq2 = 0; + rtx temp_dest, temp_dest1, temp_dest2; + unsigned int cost1 = 0, cost2 = 0; + bool speed_p = if_info->speed_p; + push_topmost_sequence (); + + { + start_sequence (); + temp_dest1 = noce_emit_cmove (if_info, temp, cond_code, + x, y, new_val, old_val, NULL_RTX); + + /* If we failed to expand the conditional move, drop out and don't + try to continue. */ + if (temp_dest1 == NULL_RTX) + { + seq1 = NULL; + cost1 = COSTS_N_INSNS (100); + } + else + { + seq1 = get_insns (); + cost1 = seq_cost (seq1, speed_p); + rtx_insn *ii; + for (ii = seq1; ii; ii = NEXT_INSN (ii)) + if (recog_memozied (ii) == -1) + cost1 += 10000; + } + end_sequence (); + } + + /* Now try emitting one passing a non-canonicalized cc comparison. + This allows the backend to emit a cmov directly without additional + compare. */ + { + start_sequence (); + temp_dest2 = noce_emit_cmove (if_info, target, cond_code, + x, y, new_val, old_val, cc_cmp); + + /* If we failed to expand the conditional move, drop out and don't + try to continue. */ + if (temp_dest2 == NULL_RTX) + { + seq2 = NULL; + cost2 = COSTS_N_INSNS (100); + } + else + { + seq2 = get_insns (); + cost2 = seq_cost (seq2, speed_p); + rtx_insn *ii; + for (ii = seq2; ii; ii = NEXT_INSN (ii)) + if (recog_memozied (ii) == -1) + cost2 += 10000; + } + end_sequence (); + } - /* If we failed to expand the conditional move, drop out and don't - try to continue. */ - if (temp_dest == NULL_RTX) + /* Check which version is less expensive. */ + if (cost1 <= cost2 && seq1 != NULL_RTX) + { + temp_dest = temp_dest1; + seq = seq1; + } + else if (seq2 != NULL_RTX) + { + /* We do not require a temp register, so remove it from the list. */ + seq = seq2; + temp_dest = temp_dest2; + temps_created.remove (temp); + } + else { + /* Nothing worked, bail out. */ + pop_topmost_sequence (); end_sequence (); - return FALSE; + return false; } + /* End the sub sequence and emit to the main sequence. */ + pop_topmost_sequence (); + emit_insn (seq); + /* Bookkeeping. */ count++; targets.safe_push (target); From patchwork Fri Aug 2 15:10:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141264 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-506117-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="BwFHjD9e"; 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 460VyC1yCjz9sML for ; Sat, 3 Aug 2019 01:12:19 +1000 (AEST) 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=N+dLtBqMHuCIeppUIbs0bgsXptZmjbcsDIFQCphgZg0ApZUPLAJLv wpDClgO7LyHt7rdZKB4a40/lNnLKiijMxo0wJdZHPocyrdVSE6FuUtEmyBjDa2/0 hXxkExRFiEcDw0J+kOAKOqv+kp9TEart3Zyoi///XQJCk/FzsTRbfQ= 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=XKUocF/8TilKqfmcreX2YT+ckGA=; b=BwFHjD9ewmghZ1fFG2xw 4GuccdDyrsSiJeLqojv+bAuNDiWuGNsMELJcyQ4q2NGMv8XFXCvvyzCCdtCqvWKb cj58bOGUNe49YEuNYQULu9VIxsuFZSm4gek6Pn12jK7f81LatHFfO0c2pFjxRJql WyngPSS9+l1PeuRGDU9L8zc= Received: (qmail 2248 invoked by alias); 2 Aug 2019 15:10:47 -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 2116 invoked by uid 89); 2 Aug 2019 15:10:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.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, UNSUBSCRIBE_BODY autolearn=ham version=3.3.1 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; Fri, 02 Aug 2019 15:10:44 +0000 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F7Gqa039412 for ; Fri, 2 Aug 2019 11:10:42 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4ntyw4uf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:41 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:39 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) 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) Fri, 2 Aug 2019 16:10:38 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72FAaMC59703540 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:37 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CF33F11C05B; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8274C11C05E; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 8/9] ifcvt: Handle swap-style idioms differently. Date: Fri, 2 Aug 2019 17:10:27 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0016-0000-0000-00000299178E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0017-0000-0000-000032F81831 Message-Id: <20190802151028.15590-9-rdapp@linux.ibm.com> X-IsSubscribed: yes A swap-style idiom like tmp = a a = b b = tmp would be transformed like tmp_tmp = cond ? a : tmp tmp_a = cond ? b : a tmp_b = cond ? tmp_tmp : b [...] including rewiring the first source operand to previous writes (e.g. tmp -> tmp_tmp). The code would recognize this, though, and change the last line to tmp_b = cond ? a : b. Without additional temporaries we can now emit the following sequence: tmp = a // (no condition here) a = cond ? b : a b = cond ? tmp : b avoiding any rewiring which would break things now. check_need_cmovs () finds swap-style idioms and marks the first of the three instructions as not needing a cmove. --- gcc/ifcvt.c | 97 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 955f9541f60..09bf443656c 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -103,6 +103,7 @@ static rtx_insn *block_has_only_trap (basic_block); static void check_need_temps (basic_block bb, hash_map *need_temp, rtx cond); +static void check_need_cmovs (basic_block bb, hash_map *need_cmov); /* Count the number of non-jump active insns in BB. */ @@ -3207,6 +3208,7 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) int count = 0; hash_map need_temps; + hash_map need_no_cmovs; /* If we newly set a CC before a cmov, we might need a temporary even though the compare will be removed by a later pass. Costing @@ -3214,6 +3216,9 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) check_need_temps (then_bb, &need_temps, cond); + /* Identify swap-style idioms. */ + check_need_cmovs (then_bb, &need_no_cmovs); + hash_map temps_created; FOR_BB_INSNS (then_bb, insn) @@ -3229,10 +3234,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) rtx new_val = SET_SRC (set); rtx old_val = target; - rtx dest = SET_DEST (set); - rtx temp; - if (need_temps.get (dest)) + if (need_temps.get (target)) { temp = gen_reg_rtx (GET_MODE (target)); temps_created.put (target, true); @@ -3241,18 +3244,11 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) 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. */ + we've changed the register allocation. Rewire the read. */ for (int i = count - 1; i >= 0; --i) if (reg_overlap_mentioned_p (new_val, targets[i])) { - /* Catch a "swap" style idiom. */ - if (find_reg_note (insn, REG_DEAD, new_val) != NULL_RTX) - /* The write to targets[i] is only live until the read - here. As the condition codes match, we can propagate - the set to here. */ - new_val = SET_SRC (single_set (unmodified_insns[i])); - else + if (find_reg_note (insn, REG_DEAD, new_val) == NULL_RTX) new_val = temporaries[i]; break; } @@ -3324,8 +3320,11 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) { start_sequence (); - temp_dest1 = noce_emit_cmove (if_info, temp, cond_code, - x, y, new_val, old_val, NULL_RTX); + if (!need_no_cmovs.get (insn)) + temp_dest1 = noce_emit_cmove (if_info, temp, cond_code, + x, y, new_val, old_val, NULL_RTX); + else + noce_emit_move_insn (target, new_val); /* If we failed to expand the conditional move, drop out and don't try to continue. */ @@ -3346,13 +3345,16 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) end_sequence (); } - /* Now try emitting one passing a non-canonicalized cc comparison. - This allows the backend to emit a cmov directly without additional + /* Now try emitting a cmov passing a non-canonicalized cc comparison. + This allows backends to emit a cmov directly without additional compare. */ { start_sequence (); - temp_dest2 = noce_emit_cmove (if_info, target, cond_code, - x, y, new_val, old_val, cc_cmp); + if (!need_no_cmovs.get (insn)) + temp_dest2 = noce_emit_cmove (if_info, target, cond_code, + x, y, new_val, old_val, cc_cmp); + else + noce_emit_move_insn (target, new_val); /* If we failed to expand the conditional move, drop out and don't try to continue. */ @@ -3931,6 +3933,7 @@ check_cond_move_block (basic_block bb, /* 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) { @@ -3938,7 +3941,7 @@ check_need_temps (basic_block bb, hash_map *need_temp, rtx cond) FOR_BB_INSNS (bb, insn) { - rtx set, dest; + rtx set, src, dest; if (!active_insn_p (insn)) continue; @@ -3947,12 +3950,68 @@ check_need_temps (basic_block bb, hash_map *need_temp, rtx cond) if (set == NULL_RTX) continue; + src = SET_SRC (set); 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); + + } +} + +/* Find local swap-style idioms in BB and mark the first insn (1) + that is only a temporary as not needing a conditional move as + it is going to be dead afterwards anyway. + + (1) int tmp = a; + a = b; + b = tmp; + + + ifcvt + --> + + load tmp,a + cmov a,b + cmov b,tmp */ + +static void +check_need_cmovs (basic_block bb, hash_map *need_cmov) +{ + rtx_insn *insn; + int count = 0; + auto_vec insns; + auto_vec dests; + + FOR_BB_INSNS (bb, insn) + { + rtx set, src, dest; + + if (!active_insn_p (insn)) + continue; + + set = single_set (insn); + if (set == NULL_RTX) + continue; + + src = SET_SRC (set); + dest = SET_DEST (set); + + for (int i = count - 1; i >= 0; --i) + { + if (reg_overlap_mentioned_p (src, dests[i]) + && find_reg_note (insn, REG_DEAD, src) != NULL_RTX) + { + need_cmov->put (insns[i], false); + } + } + + insns.safe_push (insn); + dests.safe_push (dest); + + count++; } } From patchwork Fri Aug 2 15:10:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1141265 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-506118-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="CmwigtsN"; 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 460VyS2RL3z9sBF for ; Sat, 3 Aug 2019 01:12:32 +1000 (AEST) 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=HWIHkZmeIOu6WUfkWRsCF3tealtVNOuungV+BBT36Oz9ZwMTyDowb nOCUUJfvi50CLANN/TCnwQOnnPAewPps3vKO9NtgPS+D5wVDP0DVurF65x8UcsAA y5iLvqNkXaPUd6Eql0w75P86fdQeR2u6Fh6HJ+8S/lSiMfczp4eGgA= 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=rxP+oYbruoUZYjGUGax3zdbRkNk=; b=CmwigtsNl695cIgo9CBP cu7IpeA6vSeXv2AjFkJHrjGpHn4J0Qz82Nnk5U610wNBQG7b+Q4cn38ZpKj1ammX J3bPFAWG5vlvWmViejQJOETCq416JNFO1ClE+uGbGLjhQdUre9rY9KBh3uSxgscj gOYeMKuzU1o3jhI0KrXaXV0= Received: (qmail 2486 invoked by alias); 2 Aug 2019 15:10:48 -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 2431 invoked by uid 89); 2 Aug 2019 15:10:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 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.1 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 15:10:45 +0000 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72F6ect006575 for ; Fri, 2 Aug 2019 11:10:44 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4p2bmdu3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2019 11:10:43 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2019 16:10:41 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) 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) Fri, 2 Aug 2019 16:10:39 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72FAb8B60227636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 15:10:37 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3467C11C04A; Fri, 2 Aug 2019 15:10:37 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6CE211C04C; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.145.35.207]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 15:10:36 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Cc: james.greenhalgh@arm.com, rdapp@linux.ibm.com Subject: [PATCH 9/9] ifcvt: Also pass reversed cc comparison. Date: Fri, 2 Aug 2019 17:10:28 +0200 In-Reply-To: <20190802151028.15590-1-rdapp@linux.ibm.com> References: <20190802151028.15590-1-rdapp@linux.ibm.com> x-cbid: 19080215-0016-0000-0000-000002991790 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080215-0017-0000-0000-000032F81832 Message-Id: <20190802151028.15590-10-rdapp@linux.ibm.com> X-IsSubscribed: yes When then and else are reversed, we would swap new_val and old_val. The same has to be done for our new code paths. Also, emit_conditional_move may perform swapping. In case we need to swap, the cc comparison also needs to be swapped and for this we pass the reversed cc comparison directly. An alternative would be to pass the constituents of the compare directly, but the functions have more than enough parameters already. --- gcc/ifcvt.c | 37 ++++++++++++++++++++++++++----------- gcc/optabs.c | 4 +++- gcc/optabs.h | 2 +- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 09bf443656c..d3959b870f6 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -777,7 +777,7 @@ static int noce_try_addcc (struct noce_if_info *); static int noce_try_store_flag_constants (struct noce_if_info *); static int noce_try_store_flag_mask (struct noce_if_info *); static rtx noce_emit_cmove (struct noce_if_info *, rtx, enum rtx_code, rtx, - rtx, rtx, rtx, rtx = NULL); + rtx, rtx, rtx, rtx = NULL, rtx = NULL); static int noce_try_cmove (struct noce_if_info *); static int noce_try_cmove_arith (struct noce_if_info *); static rtx noce_get_alt_condition (struct noce_if_info *, rtx, rtx_insn **); @@ -1660,7 +1660,8 @@ noce_try_store_flag_mask (struct noce_if_info *if_info) static rtx noce_emit_cmove (struct noce_if_info *if_info, rtx x, enum rtx_code code, - rtx cmp_a, rtx cmp_b, rtx vfalse, rtx vtrue, rtx cc_cmp) + rtx cmp_a, rtx cmp_b, rtx vfalse, rtx vtrue, rtx cc_cmp, + rtx rev_cc_cmp) { rtx target ATTRIBUTE_UNUSED; int unsignedp ATTRIBUTE_UNUSED; @@ -1708,7 +1709,7 @@ noce_emit_cmove (struct noce_if_info *if_info, rtx x, enum rtx_code code, target = emit_conditional_move (x, code, cmp_a, cmp_b, VOIDmode, vtrue, vfalse, GET_MODE (x), - unsignedp, cc_cmp); + unsignedp, cc_cmp, rev_cc_cmp); if (target) return target; @@ -3197,6 +3198,7 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) rtx_code cond_code = GET_CODE (cond); rtx cc_cmp = noce_get_compare (jump, false); + rtx rev_cc_cmp = noce_get_compare (jump, if_info->then_else_reversed); /* The true targets for a conditional move. */ auto_vec targets; @@ -3313,7 +3315,7 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) */ rtx_insn *seq, *seq1 = 0, *seq2 = 0; - rtx temp_dest, temp_dest1, temp_dest2; + rtx temp_dest, temp_dest1 = NULL_RTX, temp_dest2 = NULL_RTX; unsigned int cost1 = 0, cost2 = 0; bool speed_p = if_info->speed_p; push_topmost_sequence (); @@ -3324,7 +3326,13 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) temp_dest1 = noce_emit_cmove (if_info, temp, cond_code, x, y, new_val, old_val, NULL_RTX); else - noce_emit_move_insn (target, new_val); + { + temp_dest1 = target; + if (if_info->then_else_reversed) + noce_emit_move_insn (target, old_val); + else + noce_emit_move_insn (target, new_val); + } /* If we failed to expand the conditional move, drop out and don't try to continue. */ @@ -3352,9 +3360,15 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) start_sequence (); if (!need_no_cmovs.get (insn)) temp_dest2 = noce_emit_cmove (if_info, target, cond_code, - x, y, new_val, old_val, cc_cmp); + x, y, new_val, old_val, cc_cmp, rev_cc_cmp); else - noce_emit_move_insn (target, new_val); + { + temp_dest2 = target; + if (if_info->then_else_reversed) + noce_emit_move_insn (target, old_val); + else + noce_emit_move_insn (target, new_val); + } /* If we failed to expand the conditional move, drop out and don't try to continue. */ @@ -3386,7 +3400,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) /* We do not require a temp register, so remove it from the list. */ seq = seq2; temp_dest = temp_dest2; - temps_created.remove (temp); + if (temps_created.get (temp)) + temps_created.remove (temp); } else { @@ -3436,7 +3451,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) /* Mark all our temporaries and targets as used. */ for (int i = 0; i < count; i++) { - set_used_flags (temporaries[i]); + if (temps_created.get(targets[i])) + set_used_flags (temporaries[i]); set_used_flags (targets[i]); } @@ -3941,7 +3957,7 @@ check_need_temps (basic_block bb, hash_map *need_temp, rtx cond) FOR_BB_INSNS (bb, insn) { - rtx set, src, dest; + rtx set, dest; if (!active_insn_p (insn)) continue; @@ -3950,7 +3966,6 @@ check_need_temps (basic_block bb, hash_map *need_temp, rtx cond) if (set == NULL_RTX) continue; - src = SET_SRC (set); dest = SET_DEST (set); /* noce_emit_cmove will emit the condition check every time it is called diff --git a/gcc/optabs.c b/gcc/optabs.c index 3ce6f8cdd30..b1d88fd58b4 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -4325,7 +4325,8 @@ emit_indirect_jump (rtx loc) rtx emit_conditional_move (rtx target, enum rtx_code code, rtx op0, rtx op1, machine_mode cmode, rtx op2, rtx op3, - machine_mode mode, int unsignedp, rtx cc_cmp) + machine_mode mode, int unsignedp, rtx cc_cmp, + rtx rev_cc_cmp) { rtx comparison; rtx_insn *last; @@ -4372,6 +4373,7 @@ emit_conditional_move (rtx target, enum rtx_code code, rtx op0, rtx op1, std::swap (op2, op3); code = reversed; swapped = true; + cc_cmp = rev_cc_cmp; } if (mode == VOIDmode) diff --git a/gcc/optabs.h b/gcc/optabs.h index c4540f87144..17b4e71ffd4 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -258,7 +258,7 @@ extern void emit_indirect_jump (rtx); /* Emit a conditional move operation. */ rtx emit_conditional_move (rtx, enum rtx_code, rtx, rtx, machine_mode, - rtx, rtx, machine_mode, int, rtx = NULL); + rtx, rtx, machine_mode, int, rtx = NULL, rtx = NULL); /* Emit a conditional negate or bitwise complement operation. */ rtx emit_conditional_neg_or_complement (rtx, rtx_code, machine_mode, rtx,