public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59159] New: Need opaque pass-through as optimization barrier
@ 2013-11-17 11:41 glisse at gcc dot gnu.org
  2013-11-17 15:31 ` [Bug c/59159] " joseph at codesourcery dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-11-17 11:41 UTC (permalink / raw)
  To: gcc-bugs

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...


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-15 21:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-17 11:41 [Bug c/59159] New: Need opaque pass-through as optimization barrier glisse at gcc dot gnu.org
2013-11-17 15:31 ` [Bug c/59159] " joseph at codesourcery dot com
2013-11-17 16:03 ` glisse at gcc dot gnu.org
2013-11-18 11:58 ` rguenth at gcc dot gnu.org
2013-11-18 12:26 ` rguenth at gcc dot gnu.org
2013-11-18 13:27 ` joseph at codesourcery dot com
2021-09-15 21:11 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).