This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53364] [4.7/4.8 Regression] Wrong code generation
- From: "foom at fuhm dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 16 May 2012 04:10:59 +0000
- Subject: [Bug c++/53364] [4.7/4.8 Regression] Wrong code generation
- Auto-submitted: auto-generated
- References: <bug-53364-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53364
--- Comment #1 from foom at fuhm dot net 2012-05-16 04:10:59 UTC ---
Asm generated. Note that at no point is anything ever actually written to the
stack, only read from it:
0000000000000000 <main>:
0: 83 3d 00 00 00 00 09 cmpl $0x9,0x0(%rip) # 7 <main+0x7>
7: 48 8d 44 24 e8 lea -0x18(%rsp),%rax
c: 48 8d 54 24 d8 lea -0x28(%rsp),%rdx
11: 48 0f 4f c2 cmovg %rdx,%rax
15: 8b 00 mov (%rax),%eax
17: c3 retq
Making what ought to be a no-op change to the program, using class "A" instead
of "B", thus:
int main() {
A a = A(10);
a = std::min(a, A(data));
return int(a);
}
causes the following, correctly working, asm to be generated. This is the same
output generated by adding "-fno-strict-aliasing" to the compile line for the
original program. See that it now does write values onto the stack locations
being read from.
(It also seems rather crazy to me that gcc doesn't optimize such a simple
program to use purely registers and no stack addresses, but I suppose that's a
different bug.)
0000000000000000 <main>:
0: 8b 15 00 00 00 00 mov 0x0(%rip),%edx # 6 <main+0x6>
6: 48 8d 44 24 e8 lea -0x18(%rsp),%rax
b: 48 8d 4c 24 d8 lea -0x28(%rsp),%rcx
10: c7 44 24 d8 0a 00 00 movl $0xa,-0x28(%rsp)
17: 00
18: 83 fa 09 cmp $0x9,%edx
1b: 89 54 24 e8 mov %edx,-0x18(%rsp)
1f: 48 0f 4f c1 cmovg %rcx,%rax
23: 8b 00 mov (%rax),%eax
25: c3 retq