From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31795 invoked by alias); 27 Jun 2012 06:49:13 -0000 Received: (qmail 31779 invoked by uid 22791); 27 Jun 2012 06:49:11 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 27 Jun 2012 06:48:59 +0000 From: "vincenzo.innocente at cern dot ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/53785] New: coalescing multiple static instances in function scope Date: Wed, 27 Jun 2012 06:49:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: vincenzo.innocente at cern dot ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-06/txt/msg01771.txt.bz2 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)