public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102294] New: structure assignment slower than memberwise initialization
@ 2021-09-12 21:59 bart.vanassche at gmail dot com
  2021-09-12 22:17 ` [Bug middle-end/102294] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: bart.vanassche at gmail dot com @ 2021-09-12 21:59 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2021-09-14  2:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12 21:59 [Bug c/102294] New: structure assignment slower than memberwise initialization bart.vanassche at gmail dot com
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

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