From patchwork Fri Sep 25 15:04:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Greenhalgh X-Patchwork-Id: 54170 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id BE74D218DB for ; Fri, 25 Sep 2015 15:06:51 +0000 (UTC) Received: by laka1 with SMTP id a1sf20983930lak.0 for ; Fri, 25 Sep 2015 08:06:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:x-original-sender :x-original-authentication-results; bh=xf7DmhUaVs6yE5ZJ9LxCc2qNKqhXstOGWx/HZU2mgf8=; b=FjMIebF08jeclDaN4MdIESkAwgvrvfnPrZBwFBcEWUq3ozKzxbM4c+9UYr2NqUPoLJ GPcWrBZYl+TgM0jH7u7XCzlAaIa+e4+T/7Iw5a6pKtLA1iLGLVO5grU0BoDJd2UTAsGY XmvGGOxZhtA6DB3ia5Jcd+RaXj8nBwvNqyRKbXpgIC88o3UrPSIOSuwiCar5JTWNfE+e muGfKDmVNaVEoxV004+m8unFG5tpHrlw0VSutfRQ3ap8oPnff9wfzrq/CFgL9TQvWTCA o9KYQ808SnRF9+edlgppA9kuVSmYC09nLreJfjdbdLjmHybok52zvQi5PlyUM1/J6oUH GAng== X-Gm-Message-State: ALoCoQlGTqJLn9J+X1yWb48Z1P5zIjJOwyazjINKF2N5RHsuJqc7TeRXASYr2RsMNOD/YbIf2I8f X-Received: by 10.152.6.201 with SMTP id d9mr1011569laa.6.1443193610512; Fri, 25 Sep 2015 08:06:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.148.143 with SMTP id w137ls193355lfd.105.gmail; Fri, 25 Sep 2015 08:06:50 -0700 (PDT) X-Received: by 10.112.132.1 with SMTP id oq1mr1800205lbb.108.1443193610378; Fri, 25 Sep 2015 08:06:50 -0700 (PDT) Received: from mail-la0-x22e.google.com (mail-la0-x22e.google.com. [2a00:1450:4010:c03::22e]) by mx.google.com with ESMTPS id ab1si1898073lbc.108.2015.09.25.08.06.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Sep 2015 08:06:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) client-ip=2a00:1450:4010:c03::22e; Received: by laclj5 with SMTP id lj5so6429681lac.3 for ; Fri, 25 Sep 2015 08:06:49 -0700 (PDT) X-Received: by 10.152.10.241 with SMTP id l17mr1783478lab.35.1443193609754; Fri, 25 Sep 2015 08:06:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp95733lbq; Fri, 25 Sep 2015 08:06:48 -0700 (PDT) X-Received: by 10.50.98.39 with SMTP id ef7mr3407501igb.2.1443193608076; Fri, 25 Sep 2015 08:06:48 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e10si3203256ioe.104.2015.09.25.08.06.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Sep 2015 08:06:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-408355-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 18049 invoked by alias); 25 Sep 2015 15:06:20 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 17943 invoked by uid 89); 25 Sep 2015 15:06:18 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=unavailable version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Sep 2015 15:06:12 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-18-fSsnlfDfRXq8Y12tZztSeg-1; Fri, 25 Sep 2015 16:05:03 +0100 Received: from e107456-lin.cambridge.arm.com ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 25 Sep 2015 16:05:02 +0100 From: James Greenhalgh To: gcc-patches@gcc.gnu.org Cc: ramana.radhakrishnan@arm.com, bernds_cb1@t-online.de, law@redhat.com, ebotcazou@libertysurf.fr, steven@gcc.gnu.org Subject: [Patch ifcvt 3/3] Create a new target hook for deciding profitability of noce if-conversion Date: Fri, 25 Sep 2015 16:04:38 +0100 Message-Id: <1443193479-10830-4-git-send-email-james.greenhalgh@arm.com> In-Reply-To: <1443193479-10830-1-git-send-email-james.greenhalgh@arm.com> References: <20150911095608.GA2448@arm.com> <1443193479-10830-1-git-send-email-james.greenhalgh@arm.com> MIME-Version: 1.0 X-MC-Unique: fSsnlfDfRXq8Y12tZztSeg-1 X-IsSubscribed: yes X-Original-Sender: james.greenhalgh@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Hi, This patch introduces a new costs hook for deciding on the profitability of an if-conversion candidate. We defer as much as possible for this decision to the target, permitting the target to vary the outcome based on the specific behaviours of a branch predictor in addition to any other target-specific knowledge that might be available. I had hoped to keep more of this generic, using rtx_costs and an additional branch weighting factor to come up with a common formula, but that proves troublesome for AArch64 where the expansion of multiple conditional moves generates multiple redundant comparisons, which we know will be later cleaned up. As a target would have to make a judgement on how much of the new sequence to cost, and can probably only do that reasonably with the old sequence as context, I just expose both parts to the target and allow them to implement whatever they feel best. Bootstrapped on aarch64-none-linux-gnu, arm-none-linux-gnueabihf and x86_64-none-linux-gnu with no issues, and checked code generation on these platforms to ensure it has not changed. OK? Thanks, James --- 2015-09-26 James Greenhalgh * target.def (costs): New hook vector. (ifcvt_noce_profitable_p): New hook. * doc/tm.texi.in: Document it. * doc/tm.texi: Regenerate. * targhooks.h (default_ifcvt_noce_profitable_p): New. * targhooks.c (default_ifcvt_noce_profitable_p): New. * ifcvt.c (noce_profitable_p): Use new target hook. diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index eb495a8..b169d7c 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -6190,6 +6190,12 @@ true for well-predicted branches. On many architectures the @code{BRANCH_COST} can be reduced then. @end defmac +@deftypefn {Target Hook} bool TARGET_COSTS_IFCVT_NOCE_PROFITABLE_P (rtx_insn *@var{seq}, struct noce_if_info *@var{info}) +This hook should return TRUE if converting the IF-THEN-ELSE blocks + described in INFO with the if-converted sequence SEQ is expected to + be profitable. +@end deftypefn + Here are additional macros which do not specify precise relative costs, but only that certain actions are more expensive than GCC would ordinarily expect. diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 92835c1..4765ec9 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -4575,6 +4575,8 @@ true for well-predicted branches. On many architectures the @code{BRANCH_COST} can be reduced then. @end defmac +@hook TARGET_COSTS_IFCVT_NOCE_PROFITABLE_P + Here are additional macros which do not specify precise relative costs, but only that certain actions are more expensive than GCC would ordinarily expect. diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index d7fc523..e5e76bc 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -794,7 +794,7 @@ static bool noce_is_profitable_p (rtx_insn *seq ATTRIBUTE_UNUSED, struct noce_if_info *if_info) { - return (if_info->branch_cost >= if_info->magic_number); + return targetm.costs.ifcvt_noce_profitable_p (seq, if_info); } /* Helper function for noce_try_store_flag*. */ diff --git a/gcc/target.def b/gcc/target.def index f330709..996f31d 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -5876,6 +5876,21 @@ DEFHOOK HOOK_VECTOR_END (mode_switching) +/* Cost functions. */ +#undef HOOK_PREFIX +#define HOOK_PREFIX "TARGET_COSTS_" +HOOK_VECTOR (TARGET_COSTS_, costs) + +DEFHOOK +(ifcvt_noce_profitable_p, + "This hook should return TRUE if converting the IF-THEN-ELSE blocks\n\ + described in INFO with the if-converted sequence SEQ is expected to\n\ + be profitable.", + bool, (rtx_insn *seq, struct noce_if_info *info), + default_ifcvt_noce_profitable_p) + +HOOK_VECTOR_END (costs) + #undef HOOK_PREFIX #define HOOK_PREFIX "TARGET_" diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 7238c8f..7b6dbe8 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -82,6 +82,7 @@ along with GCC; see the file COPYING3. If not see #include "gimplify.h" #include "stringpool.h" #include "tree-ssanames.h" +#include "ifcvt.h" bool @@ -1922,4 +1923,14 @@ can_use_doloop_if_innermost (const widest_int &, const widest_int &, return loop_depth == 1; } +/* For the default implementation, match the legacy logic by simply + comparing the estimated branch cost against a magic number. */ + +bool +default_ifcvt_noce_profitable_p (rtx_insn *seq ATTRIBUTE_UNUSED, + struct noce_if_info *if_info) +{ + return (if_info->branch_cost >= if_info->magic_number); +} + #include "gt-targhooks.h" diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 5ae991d..076d513 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -240,4 +240,7 @@ extern void default_setup_incoming_vararg_bounds (cumulative_args_t ca ATTRIBUTE tree type ATTRIBUTE_UNUSED, int *pretend_arg_size ATTRIBUTE_UNUSED, int second_time ATTRIBUTE_UNUSED); + +extern bool default_ifcvt_noce_profitable_p (rtx_insn *, + struct noce_if_info *); #endif /* GCC_TARGHOOKS_H */