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: 698813 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tPblw5yw4z9t0G for ; Thu, 24 Nov 2016 21:58:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wkOUAcS8"; dkim-atps=neutral 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=PQgjrGr+XnhJysoJd+e4rOgzZELnbSSN0r7iMrZsPowdYV6Z/P3e1 4KaQh8FD/TP5rpQPRRKB5yGGnF+n3bDSQodb1wxJ237DRR5TWZOM/eecFdj6dMsC gjlNKGI2hxz/V7lfaVtZrjLOVp0XyrWCAee6JcMWJsXqO9R6je+9Ns= 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=wkOUAcS8ALRK/ywVZ9tR apA1aXp2gZ1q3zzsXqE6J4WrbiXz4KAcGMAd+WecBQirQREkHk5OsXfIJuwdg22f vwaDc4FcRtt7kfYs3BZT5l83kpfDZ/zhqVHNsb/UoGz4AHkVyYq8KsgM79dehWbn He4p3EiH/SGOAv+pTNbu6Ho= 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;