This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/17332] New: templated code optimization fails on fixed boolean template parameter
- From: "yuri at tsoft dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Sep 2004 07:46:56 -0000
- Subject: [Bug c++/17332] New: templated code optimization fails on fixed boolean template parameter
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I have piece of code that I compile in 2 variants:
w/out and with boolean template parameter in one class.
This boolean template parameter just includes some
extra code if turned on. It's defined in compile time as
false therefore should make no difference in program
logic in this case.
Runtime of optimized final code with template parameter
is 2 times longer than when this template parameter is
not defined at all.
PROBLEM: runtime depends on presense of template parameter
that obviously makes no difference.
I expect runtime to be insensitive to this kind of
template parameter.
Code below demonstrated the problem,
one of the first two lines should be uncommented.
First line enables template parameter,
second one disables it.
-----------------------------------------------------
#define TMPL(stmt...) stmt
//#define TMPL(stmt...)
#define SZ 50000000
char c1[SZ];
char c2[SZ];
template <class W>
class Scanner {
public: inline void scan() {
W w;
char *pc1 = &c1[0], *pc2 = &c2[0];
for (int idx = 0; idx < SZ; idx++) {
w.work(pc1++, pc2++);
}
}
};
TMPL(template <bool b>)
class C {
public: void work(char *p1, char *p2);
};
TMPL(template <bool b>)
void C TMPL(<b>) ::work(char *p1, char *p2) {
TMPL(if (b)
p2[6] += *p2;)
*p2 = *p1;
TMPL(if (b)
p2[6] -= *p2;)
}
main() {
Scanner<C TMPL(<false>) > sc;
sc.scan();
}
--
Summary: templated code optimization fails on fixed boolean
template parameter
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yuri at tsoft dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: FreeBSD 5.1-RELEASE FreeBSD 5.1-RELEASE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17332