This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/8781: Pessimization of functional-style code
- From: wesslen at users dot sourceforge dot net
- To: gcc-gnats at gcc dot gnu dot org
- Date: 2 Dec 2002 10:23:42 -0000
- Subject: c++/8781: Pessimization of functional-style code
- Reply-to: wesslen at users dot sourceforge dot net
>Number: 8781
>Category: c++
>Synopsis: Pessimization of functional-style code
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Mon Dec 02 02:26:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Daniel Wesslén
>Release: gcc version 3.3 20021125 (experimental)
>Organization:
>Environment:
CYGWIN_NT-5.1 DANIEL-P4 1.3.17(0.67/3/2) 2002-11-27 18:54 i686 unknown
>Description:
Functional programming style constructs makes g++ generate unneccesary stores.
>How-To-Repeat:
A somewhat modified version of the program submitted by AWLaFramboise in http://gcc.gnu.org/ml/gcc/2002-11/msg01012.html follows. Compile this with -O3.
/// begin
int f();
template<typename predicate>
class noop_t {
const predicate &pred;
public:
explicit noop_t(const predicate &p) : pred(p) {}
int operator()() const { return pred(); }
};
template<typename predicate>
inline noop_t<predicate> noop(const predicate pred) {
return noop_t<predicate>(pred);
}
int x()
{
return (noop(noop(noop(noop(noop(noop(noop(noop(noop(f)))))))))());
}
/// end
Compiled with -O3, the following code is generated.
.globl __Z1xv
.def __Z1xv; .scl 2; .type 32; .endef
__Z1xv:
pushl %ebp
movl %esp, %ebp
leal -4(%ebp), %ecx
leal -12(%ebp), %eax
subl $40, %esp
movl %ecx, -12(%ebp)
leal -8(%ebp), %edx
movl %eax, -16(%ebp)
leal -16(%ebp), %ecx
movl %edx, -4(%ebp)
leal -20(%ebp), %eax
movl %ecx, -20(%ebp)
leal -32(%ebp), %edx
movl %eax, -24(%ebp)
leal -24(%ebp), %ecx
movl $__Z1fv, -8(%ebp)
leal -28(%ebp), %eax
movl %ecx, -28(%ebp)
movl %eax, -32(%ebp)
movl %edx, -36(%ebp)
call __Z1fv
movl %ebp, %esp
popl %ebp
ret
.def __Z1fv; .scl 3; .type 32; .endef
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: