public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope
@ 2012-06-27  6:49 vincenzo.innocente at cern dot ch
  2012-06-27  6:59 ` [Bug rtl-optimization/53785] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-06-27  6:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53785

             Bug #: 53785
           Summary: coalescing multiple static instances in function scope
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincenzo.innocente@cern.ch


I come across this kind of pattern (repeated over and over in many functions)

    static const EvtId DM=EvtPDL::getId("D-");
    static const EvtId DP=EvtPDL::getId("D+");
    static const EvtId D0=EvtPDL::getId("D0");
    static const EvtId D0B=EvtPDL::getId("anti-D0");
    static const EvtId KM=EvtPDL::getId("K-");
    static const EvtId KP=EvtPDL::getId("K+");
    static const EvtId K0=EvtPDL::getId("K0");
    static const EvtId KB=EvtPDL::getId("anti-K0");
    static const EvtId KL=EvtPDL::getId("K_L0");
    static const EvtId KS=EvtPDL::getId("K_S0");
    static const EvtId PIM=EvtPDL::getId("pi-");
    static const EvtId PIP=EvtPDL::getId("pi+");
    static const EvtId PI0=EvtPDL::getId("pi0");

that materialized in
nm -C statics.so | grep " b "
0000000000003908 b guard variable for a1::bar(int)::D0
00000000000038e8 b guard variable for a1::bar(int)::DM
00000000000038f8 b guard variable for a1::bar(int)::DP
0000000000003948 b guard variable for a1::bar(int)::K0
0000000000003958 b guard variable for a1::bar(int)::KB
0000000000003968 b guard variable for a1::bar(int)::KL
0000000000003928 b guard variable for a1::bar(int)::KM
0000000000003938 b guard variable for a1::bar(int)::KP
0000000000003978 b guard variable for a1::bar(int)::KS
0000000000003918 b guard variable for a1::bar(int)::D0B
00000000000039a8 b guard variable for a1::bar(int)::PI0
0000000000003988 b guard variable for a1::bar(int)::PIM
0000000000003998 b guard variable for a1::bar(int)::PIP
0000000000003910 b a1::bar(int)::D0
00000000000038f0 b a1::bar(int)::DM
0000000000003900 b a1::bar(int)::DP
0000000000003950 b a1::bar(int)::K0
0000000000003960 b a1::bar(int)::KB
0000000000003970 b a1::bar(int)::KL
0000000000003930 b a1::bar(int)::KM
0000000000003940 b a1::bar(int)::KP
0000000000003980 b a1::bar(int)::KS
0000000000003920 b a1::bar(int)::D0B
00000000000039b0 b a1::bar(int)::PI0
0000000000003990 b a1::bar(int)::PIM
00000000000039a0 b a1::bar(int)::PIP


which generates a huge "bss" and most probably also a serious performance
penalty due to all those gard variables

I worked around with this simple transformation
    static struct {
      const EvtId DM=EvtPDL::getId("D-");
      const EvtId DP=EvtPDL::getId("D+");
      const EvtId D0=EvtPDL::getId("D0");
      const EvtId D0B=EvtPDL::getId("anti-D0");
      const EvtId KM=EvtPDL::getId("K-");
      const EvtId KP=EvtPDL::getId("K+");
      const EvtId K0=EvtPDL::getId("K0");
      const EvtId KB=EvtPDL::getId("anti-K0");
      const EvtId KL=EvtPDL::getId("K_L0");
      const EvtId KS=EvtPDL::getId("K_S0");
      const EvtId PIM=EvtPDL::getId("pi-");
      const EvtId PIP=EvtPDL::getId("pi+");
      const EvtId PI0=EvtPDL::getId("pi0");
    } const parts;

so I am wandering if the complier would be able to do something similar,
recognizing that all those static objects can, after all, be guarded by just
one variable (I think this will work no matter what side effects getId has)


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

* [Bug rtl-optimization/53785] coalescing multiple static instances in function scope
  2012-06-27  6:49 [Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope vincenzo.innocente at cern dot ch
@ 2012-06-27  6:59 ` pinskia at gcc dot gnu.org
  2012-06-28  4:43 ` vincenzo.innocente at cern dot ch
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-06-27  6:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53785

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-06-27 06:59:08 UTC ---
The question comes, do we want to have a lock for each variable or one for the
scope?  One for each variable was easier to implement and might be more
correct.  What happens if getId has weird side effects depending on which
thread calls it?


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

* [Bug rtl-optimization/53785] coalescing multiple static instances in function scope
  2012-06-27  6:49 [Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope vincenzo.innocente at cern dot ch
  2012-06-27  6:59 ` [Bug rtl-optimization/53785] " pinskia at gcc dot gnu.org
@ 2012-06-28  4:43 ` vincenzo.innocente at cern dot ch
  2024-03-17  0:02 ` [Bug c++/53785] " pinskia at gcc dot gnu.org
  2024-03-17  0:03 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-06-28  4:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53785

--- Comment #2 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2012-06-28 04:43:27 UTC ---
I think that no one can rely on the way statics are initialized to tune side
effects.
The only things to guarantee are that is guarded and, I think, that the order
is preserved (because of possible side effects). in case getId is inlined even
the order can be optimized in my opinion...

Now one can have race conditions, so getId could actually be called by
different threads in a unpredictable way. With a single gard it will become a
unique critical section (or a sort of transactional memory block).
Maybe experts in initialization in multi-threaded environments shall comment
further...


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

* [Bug c++/53785] coalescing multiple static instances in function scope
  2012-06-27  6:49 [Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope vincenzo.innocente at cern dot ch
  2012-06-27  6:59 ` [Bug rtl-optimization/53785] " pinskia at gcc dot gnu.org
  2012-06-28  4:43 ` vincenzo.innocente at cern dot ch
@ 2024-03-17  0:02 ` pinskia at gcc dot gnu.org
  2024-03-17  0:03 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-17  0:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|tree-optimization           |c++
   Last reconfirmed|                            |2024-03-17
     Ever confirmed|0                           |1
           Keywords|                            |ABI

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/53785] coalescing multiple static instances in function scope
  2012-06-27  6:49 [Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope vincenzo.innocente at cern dot ch
                   ` (2 preceding siblings ...)
  2024-03-17  0:02 ` [Bug c++/53785] " pinskia at gcc dot gnu.org
@ 2024-03-17  0:03 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-17  0:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |antoshkka at gmail dot com

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 87692 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2024-03-17  0:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-27  6:49 [Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope vincenzo.innocente at cern dot ch
2012-06-27  6:59 ` [Bug rtl-optimization/53785] " pinskia at gcc dot gnu.org
2012-06-28  4:43 ` vincenzo.innocente at cern dot ch
2024-03-17  0:02 ` [Bug c++/53785] " pinskia at gcc dot gnu.org
2024-03-17  0:03 ` 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).