public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95792] New: Failure to optimize assignment of struct members to memset
@ 2020-06-20 21:45 gabravier at gmail dot com
  2020-06-20 22:44 ` [Bug tree-optimization/95792] " gabravier at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-06-20 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95792
           Summary: Failure to optimize assignment of struct members to
                    memset
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

#define F0(a) i##a, 
#define F1(a) F0(a##0) F0(a##1) F0(a##2) F0(a##3) F0(a##4) F0(a##5) F0(a##6)
F0(a##7)
#define F2(a) F1(a##0) F1(a##1) F1(a##2) F1(a##3) F1(a##4) F1(a##5) F1(a##6)
F1(a##7)
#define F3(a) F2(a##0) F2(a##1) F2(a##2) F2(a##3) F2(a##4) F2(a##5) F2(a##6)
F2(a##7)
#define F4(a) F3(a##0) F3(a##1) F3(a##2) F3(a##3) F3(a##4) F3(a##5) F3(a##6)
F3(a##7)

#define H0(a) s->i##a = 0;
#define H1(a) H0(a##0) H0(a##1) H0(a##2) H0(a##3) H0(a##4) H0(a##5) H0(a##6)
H0(a##7)
#define H2(a) H1(a##0) H1(a##1) H1(a##2) H1(a##3) H1(a##4) H1(a##5) H1(a##6)
H1(a##7)
#define H3(a) H2(a##0) H2(a##1) H2(a##2) H2(a##3) H2(a##4) H2(a##5) H2(a##6)
H2(a##7)
#define H4(a) H3(a##0) H3(a##1) H3(a##2) H3(a##3) H3(a##4) H3(a##5) H3(a##6)
H3(a##7)

struct foo {
        int
        F4(0)
        bar;
};

void f (struct foo *s)
{
        H4(0)
}

With -O3, GCC "optimizes" this by storing words containing 0 for the entire
struct. LLVM instead just calls memset, which looks more reasonable.

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

* [Bug tree-optimization/95792] Failure to optimize assignment of struct members to memset
  2020-06-20 21:45 [Bug tree-optimization/95792] New: Failure to optimize assignment of struct members to memset gabravier at gmail dot com
@ 2020-06-20 22:44 ` gabravier at gmail dot com
  2020-06-22  8:22 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-06-20 22:44 UTC (permalink / raw)
  To: gcc-bugs

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

Gabriel Ravier <gabravier at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization

--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
Also to note is the fact that this takes a very long time to compile
(comparatively to LLVM) so this optimization could improve compile times by
itself.

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

* [Bug tree-optimization/95792] Failure to optimize assignment of struct members to memset
  2020-06-20 21:45 [Bug tree-optimization/95792] New: Failure to optimize assignment of struct members to memset gabravier at gmail dot com
  2020-06-20 22:44 ` [Bug tree-optimization/95792] " gabravier at gmail dot com
@ 2020-06-22  8:22 ` rguenth at gcc dot gnu.org
  2020-06-22 10:53 ` jakub at gcc dot gnu.org
  2021-12-20  4:51 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-22  8:22 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |compile-time-hog
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-06-22

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC doesn't try to do memcpy pattern detection when you manually produce such
kind of initialization.  In theory vectorizer dataref analysis figures it out
but then there's no "vectorize with memset" implemented ;)  store-merging
only merges up to word-size stores.

As expected most of the compile-time is spent funneling this through
optimizers before the very late attempts to optimize it.  Notably

 alias stmt walking                 :  35.95 ( 64%)   0.47 ( 65%)  36.60 ( 64%)
      0 kB (  0%)
 tree DSE                           :  16.08 ( 29%)   0.14 ( 19%)  16.28 ( 28%)
      0 kB (  0%)

where the walking cut-off for DSE is likely too big (note the above is
for a -O0 optimized cc1 with -O1 -fno-checking).

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

* [Bug tree-optimization/95792] Failure to optimize assignment of struct members to memset
  2020-06-20 21:45 [Bug tree-optimization/95792] New: Failure to optimize assignment of struct members to memset gabravier at gmail dot com
  2020-06-20 22:44 ` [Bug tree-optimization/95792] " gabravier at gmail dot com
  2020-06-22  8:22 ` rguenth at gcc dot gnu.org
@ 2020-06-22 10:53 ` jakub at gcc dot gnu.org
  2021-12-20  4:51 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-22 10:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
store-merging could do this, just rewrite it into MEM[whatever] = {}; if it is
large and let the expansion deal with it.

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

* [Bug tree-optimization/95792] Failure to optimize assignment of struct members to memset
  2020-06-20 21:45 [Bug tree-optimization/95792] New: Failure to optimize assignment of struct members to memset gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-06-22 10:53 ` jakub at gcc dot gnu.org
@ 2021-12-20  4:51 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-20  4:51 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
   Last reconfirmed|2020-06-22 00:00:00         |2021-12-19

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

end of thread, other threads:[~2021-12-20  4:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-20 21:45 [Bug tree-optimization/95792] New: Failure to optimize assignment of struct members to memset gabravier at gmail dot com
2020-06-20 22:44 ` [Bug tree-optimization/95792] " gabravier at gmail dot com
2020-06-22  8:22 ` rguenth at gcc dot gnu.org
2020-06-22 10:53 ` jakub at gcc dot gnu.org
2021-12-20  4:51 ` 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).