From patchwork Fri Dec 2 16:00:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 86322 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp395108obb; Fri, 2 Dec 2016 08:00:47 -0800 (PST) X-Received: by 10.99.117.71 with SMTP id f7mr80286211pgn.126.1480694447629; Fri, 02 Dec 2016 08:00:47 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b8si5745115ple.140.2016.12.02.08.00.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Dec 2016 08:00:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-443349-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-443349-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-443349-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=opCSpe1+3jbL/cSKvFJd7UAxoysoPqvMGTqxmTL1ut3aEyxXW0 rCafcT8KuRQa4YWmnHFcZa2/aXMaeEiYA9elRVWGrKEU+xtzgB0frF8sy5j6gRsQ pwwb5f4ZZoWCUS+kbTTrSzmWQKRTAZ3VcPqlWwk1CVbyGTvct/S5EDsP0= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=rTkFf2JL6L2uGrYaL26VoqCNlIw=; b=gkU+MyBIoUaSR3P/TZTx +Q0t2KP8Bw+IaC8GqtomuAn/p6rfBFmFOYnYSBaDO1VZ0tcMZdDjRlKuI3mZG60v ePBh3InH2evMB1unYDHsjrPubmR71Arhkaa5YoZBoEZvkyPxfEJ2svTHV0K2XHI7 rWrVwTKg1wdldN27Akx1FMo= Received: (qmail 121526 invoked by alias); 2 Dec 2016 16:00:25 -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 121342 invoked by uid 89); 2 Dec 2016 16:00:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=bearing, arrived X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Dec 2016 16:00:15 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6419A61B8A; Fri, 2 Dec 2016 16:00:07 +0000 (UTC) Received: from localhost.localdomain ([10.36.126.26]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB2G05fd014762; Fri, 2 Dec 2016 11:00:06 -0500 To: GCC Patches , James Greenhalgh , Uros Bizjak , Yuri Rumyantsev From: Bernd Schmidt Subject: PR78634: ifcvt/i386 cost updates Message-ID: Date: Fri, 2 Dec 2016 17:00:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes With the i386 backend no longer double-counting the cost of a SET, the default implementation default_max_noce_ifcvt_seq_cost now provides too high a bound for if conversion, allowing very costly substitutions. The following patch fixes this by making an i386 variant of the hook, but first - James, do you recall how you arrived at the COSTS_N_INSNS(3) magic number? What happens on arm if you lower that in the default hook? The change in ifcvt.c seems to have no bearing on the PR, I just noticed we were missing a cost check in one place. Lightly tested so far, will bootstrap & test on x86_64-linux. Bernd PR rtl-optimization/78634 * config/i386/i386.c (ix86_max_noce_ifcvt_seq_cost): New function. (TARGET_MAX_NOCE_IFCVT_SEQ_COST): Define. * ifcvt.c (noce_try_cmove): Add missing cost check. Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c (revision 242958) +++ gcc/config/i386/i386.c (working copy) @@ -50301,6 +50301,28 @@ ix86_spill_class (reg_class_t rclass, ma return NO_REGS; } +/* Implement TARGET_MAX_NOCE_IFCVT_SEQ_COST. Like the default implementation, + but returns a lower bound. */ + +static unsigned int +ix86_max_noce_ifcvt_seq_cost (edge e) +{ + bool predictable_p = predictable_edge_p (e); + + enum compiler_param param + = (predictable_p + ? PARAM_MAX_RTL_IF_CONVERSION_PREDICTABLE_COST + : PARAM_MAX_RTL_IF_CONVERSION_UNPREDICTABLE_COST); + + /* If we have a parameter set, use that, otherwise take a guess using + BRANCH_COST. */ + if (global_options_set.x_param_values[param]) + return PARAM_VALUE (param); + else + return BRANCH_COST (true, predictable_p) * COSTS_N_INSNS (2); +} + + /* Implement targetm.vectorize.init_cost. */ static void * @@ -51615,6 +51637,8 @@ ix86_run_selftests (void) #undef TARGET_EXPAND_DIVMOD_LIBFUNC #define TARGET_EXPAND_DIVMOD_LIBFUNC ix86_expand_divmod_libfunc +#undef TARGET_MAX_NOCE_IFCVT_SEQ_COST +#define TARGET_MAX_NOCE_IFCVT_SEQ_COST ix86_max_noce_ifcvt_seq_cost #if CHECKING_P #undef TARGET_RUN_TARGET_SELFTESTS #define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests Index: gcc/ifcvt.c =================================================================== --- gcc/ifcvt.c (revision 242958) +++ gcc/ifcvt.c (working copy) @@ -1826,7 +1826,7 @@ noce_try_cmove (struct noce_if_info *if_ noce_emit_move_insn (if_info->x, target); seq = end_ifcvt_sequence (if_info); - if (!seq) + if (!seq || !noce_conversion_profitable_p (seq, if_info)) return FALSE; emit_insn_before_setloc (seq, if_info->jump,