This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8935: Failure to apply trivial peephole optimizations
- From: martin at xemacs dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 14 Dec 2002 10:42:21 -0000
- Subject: c++/8935: Failure to apply trivial peephole optimizations
- Reply-to: martin at xemacs dot org
>Number: 8935
>Category: c++
>Synopsis: Failure to apply trivial peephole optimizations
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Sat Dec 14 02:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Martin Buchholz
>Release: gcc-3.2.1
>Organization:
>Environment:
Linux x86
>Description:
Some very easy optimizations are being missed on x86 at -O3.
The x86 asm for a function that effectively does { return 0; } is
pushl %ebp
xorl %eax, %eax
movl %esp, %ebp
subl $40, %esp
movl %ebp, %esp
popl %ebp
ret
A trivial peephole optimizer with a two instruction window can convert
the sequence
subl $40, %esp
movl %ebp, %esp
to
movl %ebp, %esp
Subsequently, we can convert the sequence
movl %esp, %ebp
movl %ebp, %esp
to
movl %esp, %ebp
leaving us with
pushl %ebp
xorl %eax, %eax
movl %esp, %ebp
subl $40, %esp
movl %ebp, %esp
popl %ebp
ret
which is the asm generated for other functions.
Detail: gcc 3.2.1, x86 Linux, g++ -O3
Entire source files follows:
struct S
{
public:
enum E { E1, E2 } e;
S (enum E ee) : e (ee) {}
S (const S&other);
operator E () { return e; }
};
bool foo () { return S::E1 == S::E2; }
bool bar () { return S::E(S(S::E1)) == S::E(S(S::E2)); }
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: