From patchwork Wed Jan 25 20:02:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 137850 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 84762B6EF7 for ; Thu, 26 Jan 2012 07:02:39 +1100 (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=1328126560; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=sVbdAWq GkXGR5vGtd765sUz+j1g=; b=Xh3okz27j8YU+RfgyQgYtjUMbsLPultDhWqGpf/ ql1cc51LqlV6TMAH7oF1M56OMruOfTBcTI8xdsUfVN7bg6EW+Zy4vbEuoGnfhgCo unqCuMOcm6P59cir9Jdw17uBLbUoyuyGy9foKmVsEKzzWOk2h6WOGwYIA/t+i3cU Mqj0= 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:X-RZG-AUTH:X-RZG-CLASS-ID:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=PRLqLii/LnET6FNgxZ2IFohzpvjQ8w9m4a6Zjht1IIpiN4UHUGJDHn41CUhB6D NwwMqgxQygBxo6ZfKNralkRBu1ZEjc5smm3qvugIymEFlMd7C9DxK+eB6PLGXKLb wG/OJIOGeYxzFQBrJwkRJl2YJhA5/Vsgm9kf0MZr+GIgU=; Received: (qmail 8706 invoked by alias); 25 Jan 2012 20:02:35 -0000 Received: (qmail 8695 invoked by uid 22791); 25 Jan 2012 20:02:34 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mo-p00-ob.rzone.de (HELO mo-p00-ob.rzone.de) (81.169.146.162) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Jan 2012 20:02:20 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT2k715jHQaJercGObUOFkj18odoYNahU4Q== X-RZG-CLASS-ID: mo00 Received: from [192.168.0.22] (business-188-111-022-002.static.arcor-ip.net [188.111.22.2]) by smtp.strato.de (jimi mo6) (RZmta 27.5 AUTH) with ESMTPA id z0116eo0PJn930 for ; Wed, 25 Jan 2012 21:02:11 +0100 (MET) Message-ID: <4F205FC3.1020107@gjlay.de> Date: Wed, 25 Jan 2012 21:02:11 +0100 From: Georg-Johann Lay User-Agent: Thunderbird 2.0.0.24 (X11/20100302) MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org Subject: [Patch] PR51374: combine.c and volatile correctness 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 This patch fixes PR51374 by more strictly updating mem_last_set. Sloppy handling of mem_last_set can lead to error in volatile correctness because combine then is allowed to drag one volatile access over an other volatile thing (volatile access, asm volatile, unspec_volatile...). As explained in the source comment, any volatile might change memory, even a volatile read. Moreover, writes of the shape (set (zero_extract (mem ... update mem_last_set. combine still optimizes volatile insn like the SFR bit accesses in the PR example if that does not require to drag one volatile over an other. Tested without regressions on i686-pc-linux-gnu Ok to apply? Johann PR rtl-optimization/51374 * combine.c (record_dead_and_set_regs_1): Update mem_last_set when reading from volatile memory or writing to mem via zero extract. Index: combine.c =================================================================== --- combine.c (revision 183472) +++ combine.c (working copy) @@ -12365,7 +12365,24 @@ record_dead_and_set_regs_1 (rtx dest, co else if (MEM_P (dest) /* Ignore pushes, they clobber nothing. */ && ! push_operand (dest, GET_MODE (dest))) - mem_last_set = DF_INSN_LUID (record_dead_insn); + { + mem_last_set = DF_INSN_LUID (record_dead_insn); + } + else if (ZERO_EXTRACT == GET_CODE (dest) + && MEM_P (XEXP (dest, 0))) + { + mem_last_set = DF_INSN_LUID (record_dead_insn); + } + + /* Even reading a volatile memory location might change memory. + One example is reading an SFR that contains a latch or that belong to + a part of a communication unit where reading a FIFO register sets some + status or busy bits located elsewhere. */ + + if (volatile_refs_p (PATTERN (record_dead_insn))) + { + mem_last_set = DF_INSN_LUID (record_dead_insn); + } } /* Update the records of when each REG was most recently set or killed