From patchwork Wed Jul 28 15:45:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 60156 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 64A29B6EF2 for ; Thu, 29 Jul 2010 01:43:37 +1000 (EST) Received: (qmail 23253 invoked by alias); 28 Jul 2010 15:43:35 -0000 Received: (qmail 23225 invoked by uid 22791); 28 Jul 2010 15:43:34 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Jul 2010 15:43:30 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6SFhLl2005770 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Jul 2010 11:43:22 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6SFhKbu009154 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 28 Jul 2010 11:43:21 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o6SFjm8O009039; Wed, 28 Jul 2010 17:45:48 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o6SFjlwT009037; Wed, 28 Jul 2010 17:45:47 +0200 Date: Wed, 28 Jul 2010 17:45:47 +0200 From: Jakub Jelinek To: Jeff Law , Maxim Kuvyrkov Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix hoisting -fcompare-debug failures (PR debug/45105) Message-ID: <20100728154547.GZ18378@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) 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 Hi! If a bb ends with a DEBUG_INSN, bb_size between -g and -g0 compilation might differ. The problem is that hoist_code forgets to count BB_END (bb) instruction (and doesn't even set to_bb_head for it, so it is left at 0). If in -g0 the block ends with a real insn and with -g with DEBUG_INSN, in the latter case the last real insn will be counted. As discussed with Maxim on IRC, we should count even the last insn. Fixed by using FOR_BB_INSNS macro, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for trunk? 2010-07-28 Jakub Jelinek PR debug/45105 * gcse.c (hoist_code): Use FOR_BB_INSNS macro. * gcc.dg/pr45105.c: New test. Jakub --- gcc/gcse.c.jj 2010-07-28 10:36:00.000000000 +0200 +++ gcc/gcse.c 2010-07-28 15:27:56.000000000 +0200 @@ -4389,21 +4389,15 @@ hoist_code (void) FOR_EACH_BB (bb) { rtx insn; - rtx bb_end; int to_head; - insn = BB_HEAD (bb); - bb_end = BB_END (bb); to_head = 0; - - while (insn != bb_end) + FOR_BB_INSNS (bb, insn) { /* Don't count debug instructions to avoid them affecting decision choices. */ if (NONDEBUG_INSN_P (insn)) to_bb_head[INSN_UID (insn)] = to_head++; - - insn = NEXT_INSN (insn); } bb_size[bb->index] = to_head; --- gcc/testsuite/gcc.dg/pr45105.c.jj 2010-07-28 15:29:00.000000000 +0200 +++ gcc/testsuite/gcc.dg/pr45105.c 2010-07-28 15:28:42.000000000 +0200 @@ -0,0 +1,27 @@ +/* PR debug/45105 */ +/* { dg-do compile } */ +/* { dg-options "-Os -fcompare-debug" } */ + +extern int *baz (int *, int *); + +void +bar (int *p1, int *p2) +{ + int n = *baz (0, 0); + p1[n] = p2[n]; +} + +void +foo (int *p, int l) +{ + int a1[32]; + int a2[32]; + baz (a1, a2); + while (l) + { + if (l & 1) + p = baz (a2, p); + l--; + bar (a1, a2); + } +}