From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23278 invoked by alias); 18 May 2011 17:24:05 -0000 Received: (qmail 23251 invoked by uid 22791); 18 May 2011 17:24:04 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 18 May 2011 17:23:50 +0000 Received: (qmail 28660 invoked from network); 18 May 2011 17:23:49 -0000 Received: from unknown (HELO ?192.168.1.68?) (vries@127.0.0.2) by mail.codesourcery.com with ESMTPA; 18 May 2011 17:23:49 -0000 Message-ID: <4DD4006E.406@codesourcery.com> Date: Wed, 18 May 2011 18:27:00 -0000 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: Zdenek Dvorak CC: gcc-patches@gcc.gnu.org Subject: [PATCH PR45098, 9/10] Cheap shift-add. References: <4DD21F6E.4050308@codesourcery.com> <4DD221FC.7060303@codesourcery.com> In-Reply-To: <4DD221FC.7060303@codesourcery.com> Content-Type: multipart/mixed; boundary="------------020606090005010906030704" Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg01299.txt.bz2 This is a multi-part message in MIME format. --------------020606090005010906030704 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-length: 927 On 05/17/2011 09:21 AM, Tom de Vries wrote: > On 05/17/2011 09:10 AM, Tom de Vries wrote: >> Hi Zdenek, >> >> I have a patch set for for PR45098. >> >> 01_object-size-target.patch >> 02_pr45098-rtx-cost-set.patch >> 03_pr45098-computation-cost.patch >> 04_pr45098-iv-init-cost.patch >> 05_pr45098-bound-cost.patch >> 06_pr45098-bound-cost.test.patch >> 07_pr45098-nowrap-limits-iterations.patch >> 08_pr45098-nowrap-limits-iterations.test.patch >> 09_pr45098-shift-add-cost.patch >> 10_pr45098-shift-add-cost.test.patch >> >> I will sent out the patches individually. >> > > OK for trunk? > > Thanks, > - Tom Resubmitting with comment. ARM has cheap shift-add instructions. Take that into account in force_expr_to_var_cost. 2011-05-05 Tom de Vries PR target/45098 * tree-ssa-loop-ivopts.c: Include expmed.h. (get_shiftadd_cost): New function. (force_expr_to_var_cost): Use get_shiftadd_cost. --------------020606090005010906030704 Content-Type: text/x-patch; name="09_pr45098-shift-add-cost.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="09_pr45098-shift-add-cost.patch" Content-length: 2635 Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 173380) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -92,6 +92,12 @@ along with GCC; see the file COPYING3. #include "tree-inline.h" #include "tree-ssa-propagate.h" +/* FIXME: add_cost and zero_cost defined in exprmed.h conflict with local uses. + */ +#include "expmed.h" +#undef add_cost +#undef zero_cost + /* FIXME: Expressions are expanded to RTL in this pass to determine the cost of different addressing modes. This should be moved to a TBD interface between the GIMPLE and RTL worlds. */ @@ -3504,6 +3510,37 @@ get_address_cost (bool symbol_present, b return new_cost (cost + acost, complexity); } + /* Calculate the SPEED or size cost of shiftadd EXPR in MODE. MULT is the + the EXPR operand holding the shift. COST0 and COST1 are the costs for + calculating the operands of EXPR. Returns true if successful, and returns + the cost in COST. */ + +static bool +get_shiftadd_cost (tree expr, enum machine_mode mode, comp_cost cost0, + comp_cost cost1, tree mult, bool speed, comp_cost *cost) +{ + comp_cost res; + tree op1 = TREE_OPERAND (expr, 1); + tree cst = TREE_OPERAND (mult, 1); + int m = exact_log2 (int_cst_value (cst)); + int maxm = MIN (BITS_PER_WORD, GET_MODE_BITSIZE (mode)); + int sa_cost; + + if (!(m >= 0 && m < maxm)) + return false; + + sa_cost = (TREE_CODE (expr) != MINUS_EXPR + ? shiftadd_cost[speed][mode][m] + : (mult == op1 + ? shiftsub1_cost[speed][mode][m] + : shiftsub0_cost[speed][mode][m])); + res = new_cost (sa_cost, 0); + res = add_costs (res, mult == op1 ? cost0 : cost1); + + *cost = res; + return true; +} + /* Estimates cost of forcing expression EXPR into a variable. */ static comp_cost @@ -3629,6 +3666,21 @@ force_expr_to_var_cost (tree expr, bool case MINUS_EXPR: case NEGATE_EXPR: cost = new_cost (add_cost (mode, speed), 0); + if (TREE_CODE (expr) != NEGATE_EXPR) + { + tree mult = NULL_TREE; + comp_cost sa_cost; + if (TREE_CODE (op1) == MULT_EXPR) + mult = op1; + else if (TREE_CODE (op0) == MULT_EXPR) + mult = op0; + + if (mult != NULL_TREE + && TREE_CODE (TREE_OPERAND (mult, 1)) == INTEGER_CST + && get_shiftadd_cost (expr, mode, cost0, cost1, mult, speed, + &sa_cost)) + return sa_cost; + } break; case MULT_EXPR: --------------020606090005010906030704--