From patchwork Tue Jul 27 16:08:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 60011 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 18711B6F10 for ; Wed, 28 Jul 2010 02:08:57 +1000 (EST) Received: (qmail 5709 invoked by alias); 27 Jul 2010 16:08:52 -0000 Received: (qmail 5620 invoked by uid 22791); 27 Jul 2010 16:08:51 -0000 X-SWARE-Spam-Status: No, hits=-1.8 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; Tue, 27 Jul 2010 16:08:45 +0000 Received: (qmail 11797 invoked from network); 27 Jul 2010 16:08:43 -0000 Received: from unknown (HELO ?84.152.198.157?) (bernds@127.0.0.2) by mail.codesourcery.com with ESMTPA; 27 Jul 2010 16:08:43 -0000 Message-ID: <4C4F0479.4090500@codesourcery.com> Date: Tue, 27 Jul 2010 18:08:25 +0200 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100724 Thunderbird/3.1.1 MIME-Version: 1.0 To: GCC Patches Subject: ARM patch: Fix an if statement in arm_rtx_costs_1 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 In the ARM rtx_costs code, there's an if statement which consists of a logical or of two conditions, the second of which always implies the first. This is nonsensical. The if statement is intended to increase the cost of operations involving frame pointer or stack pointer, except for those where the second operand is constant. This exception is broken by the presumably incorrect code, and even (plus (sp) (const)) is given a high cost. This prevents some transformations in the new postreload optimization I added a while ago. Interestingly it's a really old bug, the code was added in 1994. The following patch fixes it; typical effects from postreload: - add r4, sp, #32 - subs r6, r4, #4 + add r6, sp, #28 It also seems to be beneficial in other ways; I've seen stack frames shrink for some functions. Ok if it tests cleanly? Bernd * config/arm/arm.c (arm_rtx_costs_1): Remove second clause from the if statement which adds extra costs to frame-related expressions. Index: config/arm/arm.c =================================================================== --- config/arm/arm.c (revision 162421) +++ config/arm/arm.c (working copy) @@ -6622,12 +6610,10 @@ arm_rtx_costs_1 (rtx x, enum rtx_code ou since then they might not be moved outside of loops. As a compromise we allow integration with ops that have a constant as their second operand. */ - if ((REG_OR_SUBREG_REG (XEXP (x, 0)) - && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0))) - && GET_CODE (XEXP (x, 1)) != CONST_INT) - || (REG_OR_SUBREG_REG (XEXP (x, 0)) - && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0))))) - *total = 4; + if (REG_OR_SUBREG_REG (XEXP (x, 0)) + && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0))) + && GET_CODE (XEXP (x, 1)) != CONST_INT) + *total = COSTS_N_INSNS (1); if (mode == DImode) {