public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/8781: Pessimization of functional-style code
@ 2002-12-02  2:26 wesslen
  0 siblings, 0 replies; only message in thread
From: wesslen @ 2002-12-02  2:26 UTC (permalink / raw)
  To: gcc-gnats

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2157 bytes --]


>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:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-12-02 10:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-02  2:26 c++/8781: Pessimization of functional-style code wesslen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).