This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/17576] New: poor optimization of calls to function objects
- From: "sebor at roguewave dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Sep 2004 23:52:56 -0000
- Subject: [Bug rtl-optimization/17576] New: poor optimization of calls to function objects
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
For the program below, the 3.4.0 optimizer generates the following suboptimal
code on SPARC. The specialization of bar() is as much as 10% slower or more
than foo() in my tests.
template <class T>
struct S
{
bool operator() (const T &a, const T &b) const {
return a < b;
}
};
const int* foo (const int *a, const int *b)
{
const int* c = a;
for (; !(a == b); ++a)
if (*c < *a)
c = a;
return c;
}
template <class F>
const int* bar (const int *a, const int *b, F f)
{
const int* c = a;
for (; !(a == b); ++a)
if (f (*c, *a))
c = a;
return c;
}
template const int* bar (const int *a, const int *b, S<int>);
.file "t.cpp"
.section ".text"
.align 4
.global _Z3fooPKiS0_
.type _Z3fooPKiS0_, #function
.proc 0104
_Z3fooPKiS0_:
.LLFB3:
!#PROLOGUE# 0
!#PROLOGUE# 1
cmp %o0, %o1
be .LL8
mov %o0, %o4
ld [%o4], %o5
.LL14:
ld [%o0], %g1
cmp %o5, %g1
bl,a .LL4
mov %o0, %o4
.LL4:
add %o0, 4, %o0
cmp %o0, %o1
bne,a .LL14
ld [%o4], %o5
.LL8:
retl
mov %o4, %o0
.LLFE3:
.size _Z3fooPKiS0_, .-_Z3fooPKiS0_
.section ".gnu.linkonce.t._Z3barI1SIiEEPKiS3_S3_T_",#alloc,#execinstr
.align 4
.weak _Z3barI1SIiEEPKiS3_S3_T_
.type _Z3barI1SIiEEPKiS3_S3_T_, #function
.proc 0104
_Z3barI1SIiEEPKiS3_S3_T_:
.LLFB5:
!#PROLOGUE# 0
!#PROLOGUE# 1
cmp %o0, %o1
be .LL24
mov %o0, %o4
ld [%o0], %g1
.LL29:
ld [%o4], %o5
cmp %o5, %g1
bl .LL21
mov 1, %g1
mov 0, %g1
.LL21:
cmp %g1, 0
bne,a .LL18
mov %o0, %o4
.LL18:
add %o0, 4, %o0
cmp %o0, %o1
bne,a .LL29
ld [%o0], %g1
.LL24:
retl
mov %o4, %o0
.LLFE5:
.size _Z3barI1SIiEEPKiS3_S3_T_, .-_Z3barI1SIiEEPKiS3_S3_T_
.ident "GCC: (GNU) 3.4.0"
--
Summary: poor optimization of calls to function objects
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sebor at roguewave dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: sparc-sun-solaris2.7
GCC host triplet: sparc-sun-solaris2.7
GCC target triplet: sparc-sun-solaris2.7
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17576