From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23250 invoked by alias); 17 Nov 2013 11:41:45 -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 23215 invoked by uid 48); 17 Nov 2013 11:41:39 -0000 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/59159] New: Need opaque pass-through as optimization barrier Date: Sun, 17 Nov 2013 11:41:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: glisse at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: 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-11/txt/msg01568.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59159 Bug ID: 59159 Summary: Need opaque pass-through as optimization barrier Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org (category:c because I am asking for a built-in, but this is more about middle/back-end) Since gcc doesn't support FENV, I often need to insert optimization barriers in my code that hide things from gcc optimizers, so it doesn't perform constant propagation, or replace x*-y with -x*y, or move operations across fesetround, etc. Note that speed is still very important, doing a store/read on a volatile variable (the most portable optimization barrier) can make the whole application 15% slower. One common way to do that is to use an inline asm like: asm volatile ("", "+g"(x)); (4.9 is the first version where this doesn't ICE all over the place on x86, use "+m" earlier) so no code is emitted but the value of x is hidden from the compiler. However, the "g" constraint doesn't include FP registers. Depending if the code is compiled for power, sparc, itanium, arm or x86_64, I need to add either "d", "e", "f", "w", or "x" (yeah, there aren't 2 using the same letter). It looks like there isn't even a letter for x87 (PR 59157). Using the more general "+X" is tempting but ICEs (PR 59155). There is at least one case this inline asm approach can never handle optimally: constants. We need the variable as asm output or it won't have any effect. But the constants are in a read-only location that is not suitable for an output operand, so with "+m" gcc copies the constant to another memory location. Ideally, there would be a __builtin_opaque built-in that does the right thing and I wouldn't have to think about it...