[Bug other/28957] New: unoptimal virtual method call.
pluto at agmk dot net
gcc-bugzilla@gcc.gnu.org
Tue Sep 5 20:54:00 GMT 2006
struct A
{
typedef void ( A::* pmf )();
virtual ~A();
virtual void foo() = 0;
};
void unoptimized_loop( A* a, A::pmf f )
{
while ( 1 )
( a->*f )();
}
void optimized_loop( A* a, A::pmf f )
{
typedef void (* pf)( A* );
pf __f = (pf)( a->*f );
while ( 1 )
__f( a );
}
both loops do the same thing with different speed impact.
$ g++ pmf_opt.cpp -Wall -c -O2 -Wno-pmf-conversions --save-temps -fverbose-asm
_Z16unoptimized_loopP1AMS_FvvE:
pushq %r12 #
movq %rsi, %r12 # f, tmp68
andl $1, %r12d #, tmp68
pushq %rbp #
leaq (%rdi,%rdx), %rbp #, tmp70
pushq %rbx #
movq %rsi, %rbx # f, f
subq $16, %rsp #,
movq %rsi, (%rsp) # f, f
movq %rdx, 8(%rsp) # f, f
.L3: testq %r12, %r12 # tmp68
movq %rbx, %rax # f, f$__pfn
je .L6 #,
movq (%rbp), %rax #, tmp69
movq -1(%rax,%rbx), %rax #, f$__pfn
.L6: movq %rbp, %rdi # tmp70, prephitmp.36
call *%rax # f$__pfn
jmp .L3
_Z14optimized_loopP1AMS_FvvE:
pushq %rbp #
movq %rdi, %rbp # a, a
pushq %rbx #
movq %rsi, %rbx # f, f$__pfn
subq $24, %rsp #,
testb $1, %sil #, f$__pfn
movq %rsi, 8(%rsp) # f, f
movq %rdx, 16(%rsp) # f, f
je .L14 #,
movq (%rdi,%rdx), %rax #* f, tmp68
movq -1(%rax,%rsi), %rbx #, f$__pfn
.L14: movq %rbp, %rdi # a, a
call *%rbx # f$__pfn
jmp .L14
--
Summary: unoptimal virtual method call.
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: other
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pluto at agmk dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28957
More information about the Gcc-bugs
mailing list