From patchwork Thu Jul 26 21:02:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Endo X-Patchwork-Id: 173510 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]) by ozlabs.org (Postfix) with SMTP id 4273B2C00B7 for ; Fri, 27 Jul 2012 07:02:34 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343941355; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Subject:From:To:Date:Content-Type:Mime-Version: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=4SxBdcbMtcXQ1VPEAMPr uKkq8/E=; b=K9AcDWnBWBM9kzbHemZjOp7PQzi11Aq9ZCforNJ5Ftzih3KvqmAO f7T26Kdq5ipNRkIgSIy7wHMckIuXcIjtAHDt+BOg8GSPALwVrWcohbDZRwCxGK/8 O8WGu3ckZXMPXtOhZyni+sPAH4iY2NCTWbxonMd7ZTypNg1mcxKKo7w= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Subject:From:To:Date:Content-Type:Mime-Version:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=mnej09hc8sZjXz476uud6oJ1h7Pux/okg/zUdNyt0/B9cRWuAsgZzUjDuemmjT H/kPK1DCql1HOYARIbjw++meDfcmLI0mJ7/d63eCg5j/ipeEI3G0MFdFY3Lg7/qD MnN798vTzvRkq29TsBmglNwEdjaYP0KdxwqGhcEwWeqkQ=; Received: (qmail 16124 invoked by alias); 26 Jul 2012 21:02:31 -0000 Received: (qmail 16116 invoked by uid 22791); 26 Jul 2012 21:02:29 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_HOSTKARMA_NO, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from mailout03.t-online.de (HELO mailout03.t-online.de) (194.25.134.81) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Jul 2012 21:02:14 +0000 Received: from fwd12.aul.t-online.de (fwd12.aul.t-online.de ) by mailout03.t-online.de with smtp id 1SuVCE-0006Az-UE; Thu, 26 Jul 2012 23:02:10 +0200 Received: from [192.168.0.100] (rPlI3BZv8hJTRZa5adfLrKgBoeY2MTUZywuofsVSmQsHwxZgiSmJ3UZ--nfokR1wT2@[87.157.58.9]) by fwd12.t-online.de with esmtp id 1SuVCD-04GG000; Thu, 26 Jul 2012 23:02:09 +0200 Message-ID: <1343336524.2185.84.camel@yam-132-YW-E178-FTW> Subject: [SH] PR 54089 - adjust shift costs From: Oleg Endo To: gcc-patches Date: Thu, 26 Jul 2012 23:02:04 +0200 Mime-Version: 1.0 X-IsSubscribed: yes 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 Hello, This adjusts the cost calculations for shifts on SH. I tried out Richard's advice ( http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01206.html ) and it seems to work OK to just leave out the mentioned CONST_INT_P case. Tested on rev 189870 with make -k check RUNTESTFLAGS="--target_board=sh-sim \{-m2/-ml,-m2/-mb,-m2a/-mb,-m2a-single/-mb,-m4/-ml,-m4/-mb,-m4-single/-ml, -m4-single/-mb,-m4a-single/-ml,-m4a-single/-mb}" and no new failures. I've also confirmed that the example function in tree-switch-conversion.c:184 now is transformed as expected. The CSiBE set shows a few improvements here and there, where these kind of transformations can be applied for when dynamic shifts are available (SH3+). For SH2 (no dynamic shifts) there also seem to be some minor improvements. OK? Cheers, Oleg ChangeLog PR target/54089 * config/sh/sh.c (shiftcosts): Remove case where first operand is a const_int. Move COSTS_N_INSNS usage into caller ... (sh_rtx_costs) ... here. Return false when shiftcosts cannot be calculated instead of MAX_COST. Index: gcc/config/sh/sh.c =================================================================== --- gcc/config/sh/sh.c (revision 189877) +++ gcc/config/sh/sh.c (working copy) @@ -2859,26 +2859,22 @@ { int value; - /* There is no pattern for constant first operand. */ - if (CONST_INT_P (XEXP (x, 0))) - return MAX_COST; - if (TARGET_SHMEDIA) - return COSTS_N_INSNS (1); + return 1; if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) { if (GET_MODE (x) == DImode && CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) == 1) - return COSTS_N_INSNS (2); + return 2; /* Everything else is invalid, because there is no pattern for it. */ - return MAX_COST; + return -1; } /* If shift by a non constant, then this will be expensive. */ if (!CONST_INT_P (XEXP (x, 1))) - return COSTS_N_INSNS (SH_DYNAMIC_SHIFT_COST); + return SH_DYNAMIC_SHIFT_COST; /* Otherwise, return the true cost in instructions. Cope with out of range shift counts more or less arbitrarily. */ @@ -2887,13 +2883,14 @@ if (GET_CODE (x) == ASHIFTRT) { int cost = ashiftrt_insns[value]; - /* If SH3, then we put the constant in a reg and use shad. */ + /* If dynamic shifts are available and profitable in this case, then we + put the constant in a reg and use shad. */ if (cost > 1 + SH_DYNAMIC_SHIFT_COST) cost = 1 + SH_DYNAMIC_SHIFT_COST; - return COSTS_N_INSNS (cost); + return cost; } else - return COSTS_N_INSNS (shift_insns[value]); + return shift_insns[value]; } /* Return the cost of an AND/XOR/IOR operation. */ @@ -3147,8 +3144,13 @@ case ASHIFT: case ASHIFTRT: case LSHIFTRT: - *total = shiftcosts (x); - return true; + { + int cost = shiftcosts (x); + if (cost < 0) + return false; + *total = COSTS_N_INSNS (cost); + return true; + } case DIV: case UDIV: