From patchwork Mon Nov 28 13:10:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pitchumani Sivanupandi X-Patchwork-Id: 84397 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1126361qgi; Mon, 28 Nov 2016 05:11:14 -0800 (PST) X-Received: by 10.84.209.143 with SMTP id y15mr48630185plh.96.1480338674825; Mon, 28 Nov 2016 05:11:14 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e4si47600083pfe.10.2016.11.28.05.11.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2016 05:11:14 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-442774-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-442774-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-442774-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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=DoSm010npqJWiPU1i Bg8uMQ81rL0bQUoHbCXAfuR3O0DAr+fkBg4mFBb0yHwrGKYzwjQm1R9L4tpy0JSB 1Nz5QEc1TyAigb2fU7uqdmajUPZK2ZY+o6jcOukpoSpWBuYJoicx7yvgoAnWWS6t +GWJL3HGXxx5w6KPwmeJCVXxO4= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=bYv2WbraZbNybaADFjuorC9 7eSA=; b=v0df33RdD773lzjex0VfNPvJUA1k1Awy2sdFu+oY2dc6jJYhMd9OUHP U57BBUTcNPmieppna9txvruNROipboU+p3fJgzBtDg9gz1BO3R21bLchBgPENJeg CkhWzd2kE4QrRDKZWcOn2zbPlqGIqdcTlkK4eoldQLXPeh1ozVzI= Received: (qmail 108279 invoked by alias); 28 Nov 2016 13:10:54 -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 108268 invoked by uid 89); 28 Nov 2016 13:10:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=NOP_EXPR, nop_expr, sk:GIMPLE_, CONVERT_EXPR X-HELO: email.microchip.com Received: from smtpout.microchip.com (HELO email.microchip.com) (198.175.253.82) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Nov 2016 13:10:43 +0000 Received: from [10.40.233.140] (10.10.76.4) by chn-sv-exch04.mchp-main.com (10.10.76.105) with Microsoft SMTP Server id 14.3.181.6; Mon, 28 Nov 2016 06:10:40 -0700 Subject: Re: [RFC, tentative patch] Adjust cost for conversion expression To: Richard Biener References: <90583097-cd60-0152-66a5-e32d6830b776@microchip.com> CC: , GCC Patches From: Pitchumani Sivanupandi Message-ID: <9867b701-9236-b03e-d8b5-11fc383c60a0@microchip.com> Date: Mon, 28 Nov 2016 18:40:37 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: On Thursday 24 November 2016 04:54 PM, Richard Biener wrote: > On Thu, 24 Nov 2016, Pitchumani Sivanupandi wrote: > >> GCC inlines small functions if the code size after expansion is not excedded. >> For test case (inline.c, avr-gcc -Os -S inline.c) code size become higher if >> 'func2' is inlined. It happens because the CONVERT_EXPR/ NOP_EXPR are >> considered >> as zero cost expression. >> >> Few conversions will cost additional instructions. For targets like AVR >> it will cost considerably as it's register size is just one byte. >> >> Attached the tentative patch that changes the CONVERT_EXPR/ NOP_EXPR cost >> to 1 if the LHS is bigger than RHS and target's word_mode. >> >> Is this Ok? >> >> Would it be reasonable if cost evaluated as below instead of constant 1? >> if (LHS PRECISION > RHS PRECISION) >> cost = LHS_PRECISION / word_mode - 1 >> else >> cost = 0 >> >> Built GCC for native with bootstrap enabled. No issues. > I believe a better check would be tree_nop_conversion_p (). Thus > > CASE_CONVERT: > return tree_nop_conversion_p (type, TREE_TYPE (op0)) ? 0 : 1; > > note that > > + rhs_code = gimple_assign_rhs_code (stmt); > + if ((rhs_code == NOP_EXPR) || (rhs_code == CONVERT_EXPR)) > + { > + cost += estimate_operator_cost (rhs_code, weights, > + gimple_assign_lhs (stmt), > + gimple_assign_rhs1 (stmt)); > + } > > is super-ugly - please simply add the type of the expression as an > additional argument (see gimple_expr_type (), but the type of the > LHS would do as well). > > Note that doing this change might require some re-tuning of > inliner params, but otherwise it's totally sensible. Thanks. Attached the revised patch. When reg-tested for x86_64 found following failures. FAIL: gcc.dg/uninit-19.c FAIL: gcc.dg/vect/vect-104.c For uninit-19.c, index to dereference float array is converted to long unsigned int and that is not tree_nop_conversion_p. This caused function cost to increase and auto inline is rejected. I think, this may be huge penalty for target like x86_64 which has rich ISA. Any suggestions to avoid hitting such targets? Regards, Pitchumani diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 6899d2a..e9f45be 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3867,19 +3867,19 @@ estimate_move_cost (tree type, bool ARG_UNUSED (speed_p)) static int estimate_operator_cost (enum tree_code code, eni_weights *weights, - tree op1 ATTRIBUTE_UNUSED, tree op2) + tree op1, tree op2, tree op0) { switch (code) { /* These are "free" conversions, or their presumed cost is folded into other operations. */ case RANGE_EXPR: - CASE_CONVERT: case COMPLEX_EXPR: case PAREN_EXPR: case VIEW_CONVERT_EXPR: return 0; - + CASE_CONVERT: + return tree_nop_conversion_p (op0, TREE_TYPE (op1)) ? 0 : 1; /* Assign cost of 1 to usual operations. ??? We may consider mapping RTL costs to this. */ case COND_EXPR: @@ -4068,13 +4068,14 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) gimple_assign_rhs1 (stmt), get_gimple_rhs_class (gimple_assign_rhs_code (stmt)) == GIMPLE_BINARY_RHS - ? gimple_assign_rhs2 (stmt) : NULL); + ? gimple_assign_rhs2 (stmt) : NULL, + gimple_expr_type (stmt)); break; case GIMPLE_COND: cost = 1 + estimate_operator_cost (gimple_cond_code (stmt), weights, gimple_op (stmt, 0), - gimple_op (stmt, 1)); + gimple_op (stmt, 1), gimple_expr_type (stmt)); break; case GIMPLE_SWITCH: @@ -4129,7 +4130,7 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) &dconst2))) return estimate_operator_cost (MULT_EXPR, weights, gimple_call_arg (stmt, 0), - gimple_call_arg (stmt, 0)); + gimple_call_arg (stmt, 0), gimple_expr_type (stmt)); break; default: