From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25530 invoked by alias); 26 Jan 2014 13:24:59 -0000 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 Received: (qmail 25417 invoked by uid 48); 26 Jan 2014 13:24:54 -0000 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/59948] Optimize std::function Date: Sun, 26 Jan 2014 13:24:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: glisse at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-01/txt/msg02700.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59948 --- Comment #1 from Marc Glisse --- (In reply to Marc Glisse from comment #0) > if (f != 0B) > // Shouldn't we know that f!=0? It is defined just above. This happens because the test in fold-const.c is: return !VAR_OR_FUNCTION_DECL_P (base) || !DECL_WEAK (base); and f is marked as weak. If I remove 'inline' or put 'static' then this code is folded to true. However, I can't easily do the same for _M_manager. The condition in fold-const.c probably needs to be weakened (no pun), as I strongly doubt it is legal to replace an inline f with 0. Note that cp/class.c contains this: /* ??? Probably should check DECL_WEAK here. */ if (t && DECL_P (t)) *nonnull = 1; which we may want to keep in sync. With f static, we get the shorter but still not so good: int m() () { struct function h; int _21; : MEM[(int (*) (int) *)&h] = f; h._M_invoker = _M_invoke; h.D.26465._M_manager = _M_manager; if (_M_manager == 0B) // Can't make it non-weak goto ; else goto ; : std::__throw_bad_function_call (); : _21 = f (1); // Did we notice the function is really f too late for inlining? std::_Function_base::_Base_manager::_M_manager (&MEM[(struct _Function_base *)&h]._M_functor, &MEM[(struct _Function_base *)&h]._M_functor, 3); // Again, not inlined h ={v} {CLOBBER}; h ={v} {CLOBBER}; //Maybe we could remove one of the clobbers somewhere along the way? return _21; } If I change fold-const.c (the condition is probably wrong, I just wanted to move forward): - return !VAR_OR_FUNCTION_DECL_P (base) || !DECL_WEAK (base); + return !VAR_OR_FUNCTION_DECL_P (base) || !DECL_WEAK (base) || DECL_DECLARED_INLINE_P (base); It removes the test _M_manager == 0, but it still inlines neither f nor _M_manager.