[Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope

vincenzo.innocente at cern dot ch gcc-bugzilla@gcc.gnu.org
Wed Jun 27 06:49:00 GMT 2012


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)



More information about the Gcc-bugs mailing list