From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30704 invoked by alias); 16 May 2012 04:11:31 -0000 Received: (qmail 30657 invoked by uid 22791); 16 May 2012 04:11:30 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 May 2012 04:11:17 +0000 From: "foom at fuhm dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/53364] [4.7/4.8 Regression] Wrong code generation Date: Wed, 16 May 2012 04:13:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: foom at fuhm dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-05/txt/msg01599.txt.bz2 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
: 0: 83 3d 00 00 00 00 09 cmpl $0x9,0x0(%rip) # 7 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
: 0: 8b 15 00 00 00 00 mov 0x0(%rip),%edx # 6 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