From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17482 invoked by alias); 19 Nov 2010 08:24:51 -0000 Received: (qmail 17473 invoked by uid 22791); 19 Nov 2010 08:24:49 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CP 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; Fri, 19 Nov 2010 08:24:40 +0000 From: "hubicka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/46554] New: Less inlining leads to CSiBE regression X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hubicka 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-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 Date: Fri, 19 Nov 2010 08:27:00 -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 X-SW-Source: 2010-11/txt/msg02426.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46554 Summary: Less inlining leads to CSiBE regression Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned@gcc.gnu.org ReportedBy: hubicka@gcc.gnu.org Created attachment 22451 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22451 testcase flex-2.5.31/regex.c The loss here is not inlining regmatch_len. The catch is that the test if (m == ((void *)0) || m->rm_so < 0) is tested before all uses of regmatch_len and thus optimized out. So it simplifies into m->rm_so < 0 test and arithmetic that ends up being cheaper than call. int regmatch_len (regmatch_t * m) { if (m == ((void *)0) || m->rm_so < 0) { return 0; } return m->rm_eo - m->rm_so; } It is used as: if (m == ((void *)0) || m->rm_so < 0) return 0; if (regmatch_len (m) < 20) s = regmatch_cpy (m, buf, src); else s = regmatch_dup (m, src); Tricky. Inliner sees it as: Analyzing function body size: regmatch_len freq: 1000 size: 2 time: 2 if (m_2(D) == 0B) freq: 898 size: 1 time: 1 D.7268_3 = m_2(D)->rm_so; 50% will be eliminated by inlining freq: 898 size: 2 time: 2 if (D.7268_3 < 0) freq: 726 size: 1 time: 1 D.7270_4 = m_2(D)->rm_eo; 50% will be eliminated by inlining freq: 726 size: 1 time: 1 D.7268_5 = m_2(D)->rm_so; 50% will be eliminated by inlining freq: 726 size: 1 time: 1 D.7269_6 = D.7270_4 - D.7268_5; freq: 1000 size: 1 time: 2 return D.7269_1; will eliminated by inlining Overall function body time: 9-3 size: 11-5 With function call overhead time: 9-15 size: 11-8 I can imagine we can try to get summary based on value ranges, instead of known constants, do early VRP and work out first test well. Even optimizing the first conditoinal away won't make it inlined, it will be still considered to have size 9, so code will be expected to grow by 1 byte. Optimizing second conditoinal is even trickier. The code can be optimized away by IP-value range propagation that would be interesting optimization to have...