From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27295 invoked by alias); 20 Jun 2019 12:08:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 27286 invoked by uid 89); 20 Jun 2019 12:08:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.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=widest_int, *loop 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; Thu, 20 Jun 2019 12:08:47 +0000 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 x5KC22d4125436 for ; Thu, 20 Jun 2019 08:08:46 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2t87xuvk3e-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Jun 2019 08:08:45 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Jun 2019 13:08:44 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) 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) Thu, 20 Jun 2019 13:08:40 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x5KC8evc24314002 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2019 12:08:40 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E2F4011C04C; Thu, 20 Jun 2019 12:08:39 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E7A611C050; Thu, 20 Jun 2019 12:08:36 +0000 (GMT) Received: from 192.168.10.101 (unknown [9.197.246.56]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Jun 2019 12:08:35 +0000 (GMT) Subject: Re: [PATCH v3 3/3] PR80791 Consider doloop cmp use in ivopts To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org, wschmidt@linux.ibm.com, bin.cheng@linux.alibaba.com, rguenther@suse.de, jakub@redhat.com, Jeff Law , Kugan Vivekanandarajah References: <1557803406-123657-1-git-send-email-linkw@linux.ibm.com> <2d897dc2-a01c-5005-6973-aad0c5930aa8@linux.ibm.com> <20190620090859.GU7313@gate.crashing.org> From: "Kewen.Lin" Date: Thu, 20 Jun 2019 12:08:00 -0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <20190620090859.GU7313@gate.crashing.org> Content-Type: multipart/mixed; boundary="------------FE8403D448C398226609C186" x-cbid: 19062012-0028-0000-0000-0000037C081D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19062012-0029-0000-0000-0000243C1A3B Message-Id: <32eb9bfd-c996-821d-730c-7c83002cf345@linux.ibm.com> X-IsSubscribed: yes X-SW-Source: 2019-06/txt/msg01223.txt.bz2 This is a multi-part message in MIME format. --------------FE8403D448C398226609C186 Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 7bit Content-length: 866 Hi Segher, > On Wed, Jun 19, 2019 at 07:47:34PM +0800, Kewen.Lin wrote: >> +/* Return true if count register for branch is supported. */ >> + >> +static bool >> +rs6000_have_count_reg_decr_p () >> +{ >> + return flag_branch_on_count_reg; >> +} > > rs6000 unconditionally supports these instructions, not just when that > flag is set. If you need to look at the flag, the *caller* of this new > hook should, not every implementation of the hook. So just "return true" > here? Good point! Updated it as hookpod. >> +/* For doloop use, if the algothrim selects some candidate which invalid for > > "algorithm", "which is invalid". >> + some cost like zero rather than original inifite cost. The point is to > > "infinite" > Thanks for catching! I should run spelling check next time. :) New version attached with comments addressed. Thanks, Kewen --------------FE8403D448C398226609C186 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="ivopts.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ivopts.diff" Content-length: 5633 diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 12f1dfd..e98aba9 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -1913,7 +1913,7 @@ static const struct attribute_spec rs6000_attribute_table[] = #define TARGET_PREDICT_DOLOOP_P rs6000_predict_doloop_p #undef TARGET_HAVE_COUNT_REG_DECR_P -#define TARGET_HAVE_COUNT_REG_DECR_P rs6000_have_count_reg_decr_p +#define TARGET_HAVE_COUNT_REG_DECR_P true #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV rs6000_atomic_assign_expand_fenv @@ -39440,14 +39440,6 @@ rs6000_predict_doloop_p (struct loop *loop) return true; } -/* Return true if count register for branch is supported. */ - -static bool -rs6000_have_count_reg_decr_p () -{ - return flag_branch_on_count_reg; -} - struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-rs6000.h" diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 46e488f..5477294 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -11618,11 +11618,13 @@ loops, and will help ivopts to make some decisions. The default version of this hook returns false. @end deftypefn -@deftypefn {Target Hook} bool TARGET_HAVE_COUNT_REG_DECR_P (void) +@deftypevr {Target Hook} bool TARGET_HAVE_COUNT_REG_DECR_P Return true if the target supports hardware count register for decrement -and branch. -The default version of this hook returns false. -@end deftypefn +and branch. This count register can't be used as general register since +moving to/from a general register from/to it is very expensive. +For the targets with this support, ivopts can take doloop use as zero cost. +The default value is false. +@end deftypevr @deftypefn {Target Hook} bool TARGET_CAN_USE_DOLOOP_P (const widest_int @var{&iterations}, const widest_int @var{&iterations_max}, unsigned int @var{loop_depth}, bool @var{entered_at_top}) Return true if it is possible to use low-overhead loops (@code{doloop_end} diff --git a/gcc/target.def b/gcc/target.def index ec15a6d..8a64e5b 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -4246,13 +4246,15 @@ The default version of this hook returns false.", bool, (struct loop *loop), default_predict_doloop_p) -DEFHOOK +DEFHOOKPOD (have_count_reg_decr_p, "Return true if the target supports hardware count register for decrement\n\ -and branch.\n\ -The default version of this hook returns false.", - bool, (void), - hook_bool_void_false) +and branch. This count register can't be used as general register since\n\ +moving to/from a general register from/to it is very expensive.\n\ +For the targets with this support, ivopts can take doloop use as zero cost.\n\ +The default value is false.", + bool, false) + DEFHOOK (can_use_doloop_p, diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ivopts-lt.c b/gcc/testsuite/gcc.dg/tree-ssa/ivopts-lt.c index 7d5859b..71d7f67 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ivopts-lt.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ivopts-lt.c @@ -17,6 +17,7 @@ f1 (char *p, uintptr_t i, uintptr_t n) while (i < n); } -/* { dg-final { scan-tree-dump-times "PHI" 1 "ivopts" } } */ -/* { dg-final { scan-tree-dump-times "PHI current_loop; @@ -6749,7 +6749,7 @@ find_optimal_iv_set_1 (struct ivopts_data *data, bool originalp) return set; } -/* For doloop use, if the algothrim selects some candidate which invalid for +/* For doloop use, if the algorithm selects some candidate which is invalid for later rewrite, fix it up with bind_cand. */ static void @@ -7622,7 +7622,7 @@ determine_scaling_factor (struct ivopts_data *data, basic_block *body) /* Find doloop comparison use and set its related bind_cand. We adjust the doloop use group cost against various IV cands, it's possible to assign - some cost like zero rather than original inifite cost. The point is to + some cost like zero rather than original infinite cost. The point is to give more chances to consider other IV cands instead of BIV. The cost originally given on doloop use can affect optimal decision because it can become dead and get eliminated but considered too much here. @@ -7744,7 +7744,8 @@ tree_ssa_iv_optimize_loop (struct ivopts_data *data, struct loop *loop, /* Finds candidates for the induction variables (item 2). */ find_iv_candidates (data); - if (targetm.have_count_reg_decr_p() && generic_predict_doloop_p (data)) + if (flag_branch_on_count_reg && targetm.have_count_reg_decr_p + && generic_predict_doloop_p (data)) { data->doloop_use_p = find_doloop_use_and_its_bind (data); if (data->doloop_use_p && dump_file && (dump_flags & TDF_DETAILS)) --------------FE8403D448C398226609C186--