From patchwork Fri Jan 21 12:38:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 79835 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 EECDDB70FF for ; Fri, 21 Jan 2011 23:39:08 +1100 (EST) Received: (qmail 28843 invoked by alias); 21 Jan 2011 12:39:07 -0000 Received: (qmail 28835 invoked by uid 22791); 21 Jan 2011 12:39:07 -0000 X-SWARE-Spam-Status: No, hits=-6.4 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; Fri, 21 Jan 2011 12:38:46 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0LCciSH019850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Jan 2011 07:38:44 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0LCchDb014114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 21 Jan 2011 07:38:44 -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 p0LCchkn013167 for ; Fri, 21 Jan 2011 13:38:43 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p0LCch5u013165 for gcc-patches@gcc.gnu.org; Fri, 21 Jan 2011 13:38:43 +0100 Date: Fri, 21 Jan 2011 13:38:43 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't optimize out accesses to const volatiles (PR tree-optimization/47391) Message-ID: <20110121123843.GF2724@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! The following testcase incorrectly optimizes i = v; into i = 1; in inlined foo into main (while keeping i = v; in foo out of line copy). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-01-21 Jakub Jelinek PR tree-optimization/47391 * varpool.c (const_value_known_p): Return false if decl is volatile. * gcc.dg/pr47391.c: New test. Jakub --- gcc/varpool.c.jj 2010-11-26 18:39:11.000000000 +0100 +++ gcc/varpool.c 2011-01-21 09:22:33.000000000 +0100 @@ -370,7 +370,7 @@ const_value_known_p (tree decl) gcc_assert (TREE_CODE (decl) == VAR_DECL); - if (!TREE_READONLY (decl)) + if (!TREE_READONLY (decl) || TREE_THIS_VOLATILE (decl)) return false; /* Gimplifier takes away constructors of local vars */ --- gcc/testsuite/gcc.dg/pr47391.c.jj 2011-01-21 09:31:33.000000000 +0100 +++ gcc/testsuite/gcc.dg/pr47391.c 2011-01-21 09:32:23.000000000 +0100 @@ -0,0 +1,22 @@ +/* PR tree-optimization/47391 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +const volatile int v = 1; +int i = 0; + +void +foo (void) +{ + i = v; +} + +int +main (void) +{ + foo (); + return 0; +} + +/* { dg-final { scan-tree-dump-not "i = 1;" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */