public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96327] New: Inefficient increment through pointer to volatile on x86
@ 2020-07-27  1:47 paulmckrcu at gmail dot com
  2020-07-27  1:56 ` [Bug c/96327] " paulmckrcu at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: paulmckrcu at gmail dot com @ 2020-07-27  1:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96327

            Bug ID: 96327
           Summary: Inefficient increment through pointer to volatile on
                    x86
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: paulmckrcu at gmail dot com
  Target Milestone: ---

Although the code generation for increment (++, --) through a pointer to
volatile has improved greatly over the past 15 years, there is a case in which
the address calculation is needlessly done separately instead of by the x86
increment instruction itself.  Here is some example code:

struct task {
    int other;
    int rcu_count;
};

struct task *current;

void rcu_read_lock()
{
    (*(volatile int*)&current->rcu_count)++;
}

As can be seen in godbolt.org (https://godbolt.org/z/fGze8E), the address
calculation is split by GCC. The shorter code sequence generated by clang/LLVM
is preferable.

Fixing this would allow the Linux kernel to use safer code sequences for
certain fastpaths, in this example, rcu_read_lock() and rcu_read_unlock() for
kernels built with CONFIG_PREEMPT=y.

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

end of thread, other threads:[~2020-07-30 19:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27  1:47 [Bug c/96327] New: Inefficient increment through pointer to volatile on x86 paulmckrcu at gmail dot com
2020-07-27  1:56 ` [Bug c/96327] " paulmckrcu at gmail dot com
2020-07-27  2:05 ` [Bug target/96327] " pinskia at gcc dot gnu.org
2020-07-27  2:06 ` pinskia at gcc dot gnu.org
2020-07-27  3:26 ` paulmckrcu at gmail dot com
2020-07-30 19:03 ` glisse at gcc dot gnu.org
2020-07-30 19:23 ` paulmckrcu at gmail dot com

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