From patchwork Tue Jan 25 19:56:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 80399 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 1242F1007D3 for ; Wed, 26 Jan 2011 06:57:00 +1100 (EST) Received: (qmail 13424 invoked by alias); 25 Jan 2011 19:56:44 -0000 Received: (qmail 13372 invoked by uid 22791); 25 Jan 2011 19:56:42 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, 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; Tue, 25 Jan 2011 19:56:36 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0PJuZ1m029210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 Jan 2011 14:56:35 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0PJuY29015597 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 25 Jan 2011 14:56:35 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p0PJuYtF012501 for ; Tue, 25 Jan 2011 20:56:34 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p0PJuXEi012500 for gcc-patches@gcc.gnu.org; Tue, 25 Jan 2011 20:56:33 +0100 Date: Tue, 25 Jan 2011 20:56:33 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix forwprop (PR tree-optimization/47265, PR tree-optimization/47443) Message-ID: <20110125195633.GG2724@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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! As discussed in the PR and on IRC, forward_propagate_addr_expr currently sometimes recurses and the recursion might update_stmt on other stmts and that might affect the iteration using FOR_EACH_IMM_USE in the outer forward_propagate_addr_expr. This patch fixes it by only returning true (thus, allowing the def_stmt to be removed) if there are no longer any non-debug uses. Bootstrapped/regtested on x86_64-linux and i686-linux, preapproved by richi on IRC, committed to trunk. 2011-01-25 Jakub Jelinek PR tree-optimization/47265 PR tree-optimization/47443 * tree-ssa-forwprop.c (forward_propagate_addr_expr): Return false if name still has some uses. * gcc.c-torture/compile/pr47265.c: New test. * gcc.dg/pr47443.c: New test. Jakub --- gcc/tree-ssa-forwprop.c.jj 2011-01-25 12:58:36.000000000 +0100 +++ gcc/tree-ssa-forwprop.c 2011-01-25 16:55:02.705433320 +0100 @@ -1114,7 +1114,7 @@ forward_propagate_addr_expr (tree name, } } - return all; + return all && has_zero_uses (name); } /* Forward propagate the comparison defined in STMT like --- gcc/testsuite/gcc.dg/pr47443.c.jj 2011-01-25 13:50:49.316388845 +0100 +++ gcc/testsuite/gcc.dg/pr47443.c 2011-01-25 13:49:56.000000000 +0100 @@ -0,0 +1,14 @@ +/* PR tree-optimization/47443 */ +/* { dg-do compile } */ +/* { dg-options "-O -fstack-check=generic" } */ + +static inline bar (char *c, int i) +{ + return c + i > c; +} + +int foo () +{ + char c[100]; + return (bar (c, 1)); +} --- gcc/testsuite/gcc.c-torture/compile/pr47265.c.jj 2011-01-25 13:48:42.563388835 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr47265.c 2011-01-25 13:48:17.000000000 +0100 @@ -0,0 +1,20 @@ +/* PR tree-optimization/47265 */ + +struct S +{ + char a[3]; + char b[3]; +}; + +void +bar (char *dst, const char *src, unsigned n) +{ + while (n--) + *dst++ = *src ? *src++ : ' '; +} + +void +foo (struct S *s) +{ + bar (s->a, s->b, 3); +}