From patchwork Thu Nov 24 10:58:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pitchumani Sivanupandi X-Patchwork-Id: 83854 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp72580qgi; Thu, 24 Nov 2016 02:58:27 -0800 (PST) X-Received: by 10.99.230.17 with SMTP id g17mr3208103pgh.82.1479985107777; Thu, 24 Nov 2016 02:58:27 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id t1si30645820pge.38.2016.11.24.02.58.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Nov 2016 02:58:27 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-442527-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-442527-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-442527-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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=MbLYcg65ZoRkI7e5xBQJPTMiwdgS9SKC6U0OGwKTFaAQUiupq5fwV VyCImTy4cnIoUyL+A8F2euiavBFALtoQoKQJhIdp0w30lo8RzPffujAERCwfgYQ0 lxFQvLfuyUERMYIhSG88ALtJzNhIrDbIeX78vJNiWWvcufWBXTnOWY= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=WSX1vFQHIvFj4+zT727KuWa9fME=; b=f4G3/lkSEDgcjR6lthOj AiSTr+ijmPx+kd8jcm4cVtX6Oovnru7xE9yvpq1rsT9ThNcRT0vnvOIF7JH+TDYY 1Qsa3NY1Olh43fmGGjU3SHRWep1H6BzHcwp2E0l31Be0QDm73uFQvOk2w718LPNu YhWaEct6hKFEqY6dWWdhs8w= Received: (qmail 36043 invoked by alias); 24 Nov 2016 10:58:06 -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 36029 invoked by uid 89); 24 Nov 2016 10:58:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=H*M:0152 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; Thu, 24 Nov 2016 10:58:03 +0000 Received: from [10.40.233.140] (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.181.6; Thu, 24 Nov 2016 03:58:01 -0700 From: Pitchumani Sivanupandi Subject: [RFC, tentative patch] Adjust cost for conversion expression To: , , GCC Patches Message-ID: <90583097-cd60-0152-66a5-e32d6830b776@microchip.com> Date: Thu, 24 Nov 2016 16:28:00 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 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. Regards, Pitchumani diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 6899d2a..dbb305d 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3867,19 +3867,28 @@ 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) { + unsigned int lhs_prec, rhs_prec; 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: + { + if (op1 && op2) { + lhs_prec = element_precision (TREE_TYPE (op1)); + rhs_prec = element_precision (TREE_TYPE (op2)); + if ((lhs_prec > rhs_prec) && (lhs_prec > word_mode)) + return 1; + } + return 0; + } /* Assign cost of 1 to usual operations. ??? We may consider mapping RTL costs to this. */ case COND_EXPR: @@ -4026,6 +4035,7 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) { unsigned cost, i; enum gimple_code code = gimple_code (stmt); + enum tree_code rhs_code; tree lhs; tree rhs; @@ -4064,9 +4074,17 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) if (gimple_assign_load_p (stmt)) cost += estimate_move_cost (TREE_TYPE (rhs), weights->time_based); - cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights, + 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)); + } + else + cost += estimate_operator_cost (rhs_code, weights, gimple_assign_rhs1 (stmt), - get_gimple_rhs_class (gimple_assign_rhs_code (stmt)) + get_gimple_rhs_class (rhs_code) == GIMPLE_BINARY_RHS ? gimple_assign_rhs2 (stmt) : NULL); break;