From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13325 invoked by alias); 21 Oct 2013 12:41:13 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 12854 invoked by uid 48); 21 Oct 2013 12:41:09 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/58805] [4.8/4.9 Regression] Inline assembly wrongly optimized out when inside a conditional Date: Mon, 21 Oct 2013 12:41:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: vries at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-10/txt/msg01500.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58805 --- Comment #15 from Richard Biener --- (In reply to vries from comment #14) > > No it shouldn't. It should return true if the stmt has side-effects that > > are _not_ explicit in the statement. This side-effect is explicitely there. > > Hmm, a rather deceptive name then, if gimple_stmt_has_side_effects does not > in fact tell whether a gimple statement has side-effects or not. > I wonder if any other use sites are mistaken in the semantics, and what > could be a better name. A side-effect is by definition an effect that happens "on the side", so I think the name quite matches. > A better name according to your description could be > gimple_stmt_has_implicit_side_effects, but I'm not sure I understand how to > differentiate between implicit and explicit here. Marking an asm with > volatile, is that implicit or explicit, and why? Well, is in a = b + c the computation of a + c a side-effect or not? Is in a = b the assignment to 'a' a side-effect or not. Neither I would argue. > AFAIU, the name gimple_stmt_has_call_or_volatile_side_effects reflects what > the implementation does. No, for calls the side-effects of the callee body are not explicit (unless it is pure or const). > Anyways, this tentative patch fixes the problem in tail-merge: > ... > Author: Tom de Vries > Date: Mon Oct 21 13:40:28 2013 +0200 > > * tree-ssa-tail-merge.c (stmt_local_def): Improve side-effect check. > > diff --git a/gcc/testsuite/gcc.dg/pr58805.c b/gcc/testsuite/gcc.dg/pr58805.c > new file mode 100644 > index 0000000..6e6eba5 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr58805.c > @@ -0,0 +1,23 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -ftree-tail-merge -fdump-tree-pre" } */ > + > +static inline void bar(unsigned long *r) > +{ > + unsigned long t; > + __asm__ ( > + "movq $42, %[t]\n\t" > + "movq %[t], %[r]\n\t" > + : [t] "=&r" (t), [r] "=r" (*r) > + ); > +} > + > +void foo(int n, unsigned long *x, unsigned long *y) > +{ > + if (n == 0) > + bar(x); > + else > + bar(y); > +} > + > +/* { dg-final { scan-tree-dump-times "__asm__" 2 "pre"} } */ > +/* { dg-final { cleanup-tree-dump "pre" } } */ > diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c > index 9094935..0090da6 100644 > --- a/gcc/tree-ssa-tail-merge.c > +++ b/gcc/tree-ssa-tail-merge.c > @@ -300,7 +300,8 @@ stmt_local_def (gimple stmt) > tree val; > def_operand_p def_p; > > - if (gimple_has_side_effects (stmt)) > + if (gimple_has_side_effects (stmt) > + || gimple_vdef (stmt) != NULL_TREE) > return false; > > def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF); > ... > > I'll test this one. Looks good to me. Btw, you'd have had the same issue with the aggregate return of a pure/const function call, no?