public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bart.vanassche at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/102294] New: structure assignment slower than memberwise initialization
Date: Sun, 12 Sep 2021 21:59:18 +0000	[thread overview]
Message-ID: <bug-102294-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102294
           Summary: structure assignment slower than memberwise
                    initialization
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bart.vanassche at gmail dot com
  Target Milestone: ---

Created attachment 51444
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51444&action=edit
Test program that illustrates the issue

The output of the attached test program is as follows for an Intel Core i7-4790
CPU (3.6 GHz) when compiled with -O2:
$ ~/test/bio_init 
Elapsed time: 0.874763 s
Elapsed time: 0.480335 s
Elapsed time: 0.733273 s

The above output shows that bio_init2() runs faster than bio_init3() and that
bio_init3() runs faster than bio_init1(). bio_init3() uses structure assignment
to initialize struct bio while bio_init2() uses memberwise initialization.
bio_init1() uses memset(). To me it was a big surprise to see that bio_init3()
is slower than bio_init2(). Apparently clang generates better code:

$ clang -O2 -o bio_init-clang bio_init.c
$ ./bio_init-clang 

Elapsed time: 0.446804 s
Elapsed time: 0.455009 s
Elapsed time: 0.407392 s

Can gcc be modified such that bio_init3() runs at least as fast as bio_init2()?

The bio_init[123]() source code comes from the Linux kernel. Optimization level
-O2 has been chosen because that is what the Linux kernel uses.

             reply	other threads:[~2021-09-12 21:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-12 21:59 bart.vanassche at gmail dot com [this message]
2021-09-12 22:17 ` [Bug middle-end/102294] " pinskia at gcc dot gnu.org
2021-09-13  1:41 ` bart.vanassche at gmail dot com
2021-09-13  1:43 ` bart.vanassche at gmail dot com
2021-09-13  1:59 ` pinskia at gcc dot gnu.org
2021-09-13  2:16 ` bart.vanassche at gmail dot com
2021-09-13  2:25 ` pinskia at gcc dot gnu.org
2021-09-13  2:57 ` [Bug middle-end/102294] memset expansion is sometimes slow for small sizes bart.vanassche at gmail dot com
2021-09-13  3:06 ` crazylht at gmail dot com
2021-09-13  3:21 ` bart.vanassche at gmail dot com
2021-09-13  3:28 ` crazylht at gmail dot com
2021-09-13  3:40 ` [Bug target/102294] " pinskia at gcc dot gnu.org
2021-09-13 13:37 ` hjl.tools at gmail dot com
2021-09-14  2:04 ` bart.vanassche at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102294-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).