Bug 33546 - [missed optimization] trivial static function not inlined.
Summary: [missed optimization] trivial static function not inlined.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.2
: P3 enhancement
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-24 18:05 UTC by Pawel Sikora
Modified: 2007-09-24 20:54 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-gnu-linux
Build:
Known to work: 4.3.0
Known to fail: 4.2.2
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2007-09-24 18:05:46 UTC
$ cat 0.cpp
template < typename R, typename T, R ( T::* method )() >
static inline R dispatch( T& object )
{
        return ( object.*method )();
}
struct X
{
        virtual ~X();
        virtual void f();
};
void test1( X& obj )
{
        void ( *f )( X& ) = dispatch< void, X, &X::f >;
        f( obj );
}
void test2( X& obj )
{
        obj.f();
}

g++-4.2.2-RC1 produces unoptimal code for test1:

test1(X&):
        jmp     void dispatch<void, X, &(X::f())>(X&)

test2(X&):
        movq    (%rdi), %rax
        movq    16(%rax), %r11
        jmp     *%r11

void dispatch<void, X, &(X::f())>(X&):
        movq    (%rdi), %rax
        movq    16(%rax), %r11
        jmp     *%r11
Comment 1 Andrew Pinski 2007-09-24 18:07:56 UTC
If this has already been fixed on the trunk, then what is the issue?
Comment 2 Paolo Carlini 2007-09-24 18:10:35 UTC
Maybe the underlying issue is tree-optimization/3713, not fixed in less-than-trivial cases?
Comment 3 Pawel Sikora 2007-09-24 18:21:16 UTC
(In reply to comment #1)
> If this has already been fixed on the trunk, then what is the issue?
> 

4.3 is not ready for production use.
4.2.2 is quite stable and this missed optimization
introduces a redundant branch which is not expected
in our heavy template code.
Comment 4 Andrew Pinski 2007-09-24 18:24:08 UTC
And enhancements only go for the next version and never on production code (release branches) (like any sane product release should happen, even physicial ones).
Comment 5 Richard Biener 2007-09-24 20:54:33 UTC
we clearly don't do enhancements for a release branch.