From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5357 invoked by alias); 24 Jan 2015 11:53:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 5267 invoked by uid 89); 24 Jan 2015 11:53:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f46.google.com Received: from mail-wg0-f46.google.com (HELO mail-wg0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 24 Jan 2015 11:53:30 +0000 Received: by mail-wg0-f46.google.com with SMTP id l2so1793586wgh.5 for ; Sat, 24 Jan 2015 03:53:27 -0800 (PST) X-Received: by 10.180.210.195 with SMTP id mw3mr13251029wic.79.1422100407658; Sat, 24 Jan 2015 03:53:27 -0800 (PST) Received: from localhost ([95.144.14.138]) by mx.google.com with ESMTPSA id gf9sm5977962wjc.0.2015.01.24.03.53.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Jan 2015 03:53:27 -0800 (PST) From: Richard Sandiford To: Segher Boessenkool Mail-Followup-To: Segher Boessenkool ,Jakub Jelinek , Richard Henderson , Richard Biener , Jeff Law , Richard Biener , Eric Botcazou , gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Cc: Jakub Jelinek , Richard Henderson , Richard Biener , Jeff Law , Richard Biener , Eric Botcazou , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Reenable CSE of non-volatile inline asm (PR rtl-optimization/63637) References: <54B59964.7070707@redhat.com> <20150114000315.GA32710@gate.crashing.org> <54B609A9.9090800@redhat.com> <20150114151906.GA21784@gate.crashing.org> <54B74AD9.4010905@redhat.com> <20150115081330.GB1405@tucnak.redhat.com> <54C2B495.2010009@redhat.com> <20150123213940.GA17134@gate.crashing.org> <20150123214850.GZ1746@tucnak.redhat.com> <20150124011858.GA31255@gate.crashing.org> Date: Sat, 24 Jan 2015 14:39:00 -0000 In-Reply-To: <20150124011858.GA31255@gate.crashing.org> (Segher Boessenkool's message of "Fri, 23 Jan 2015 19:18:58 -0600") Message-ID: <87lhkse6o9.fsf@googlemail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2015-01/txt/msg02172.txt.bz2 Segher Boessenkool writes: > On Fri, Jan 23, 2015 at 10:48:50PM +0100, Jakub Jelinek wrote: >> On Fri, Jan 23, 2015 at 03:39:40PM -0600, Segher Boessenkool wrote: >> > I understand that argument. But it is not what GCC actually does, nor >> > what I think it should do. Consider this program: >> > >> > --- 8< --- >> > int main(void) >> > { >> > int x[100], y[100]; >> > >> > x[31] = 42; >> > >> > asm("# eww %0" : "=m"(y[4]) : : "memory"); >> > >> > return 0; >> > } >> > --- 8< --- >> >> Here x isn't addressable, so it is certainly fine to DSE it. >> x shouldn't be considered memory. >> If the address of x escaped, either to the assembly or to some global var >> etc., then it probably shouldn't be removed. > > But GCC does consider it memory. If you look at the (tree) dump files > you see both arrays are clobbered after the asm. Tree DCE removes the > store to x[31] nevertheless. > > If the address of x escapes then of course the store to x[31] should > not be removed, irrespective of whether the clobber implies a read > or not. Just tried some other examples out of curiosity. In: int main(void) { int x[100], y[100]; asm volatile("# foo" :: "r"(x)); x[31] = 42; asm("# eww %0" : "=m"(y[4]) : : "memory"); return 0; } "x[31]" can only validly escape to the second asm. In this case the assignment is kept, as it is with: int main(void) { int x[100], y; asm volatile("# foo" :: "r"(x)); x[31] = 42; asm("# eww %0" : "=r"(y) : : "memory"); return y; } But remove the clobber and it goes away: int main(void) { int x[100], y; asm volatile("# foo" :: "r"(x)); x[31] = 42; asm("# eww %0" : "=r"(y)); return y; } So it looks like these four cases (including yours) are handled correctly. Thanks, Richard