From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13645 invoked by alias); 19 Oct 2013 11:01:14 -0000 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 Received: (qmail 13624 invoked by uid 48); 19 Oct 2013 11:01:10 -0000 From: "Jeremie.Detrey at loria dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug inline-asm/58805] New: Inline assembly wrongly optimized out when inside a conditional Date: Sat, 19 Oct 2013 11:01:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: inline-asm X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Jeremie.Detrey at loria dot fr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-10/txt/msg01349.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58805 Bug ID: 58805 Summary: Inline assembly wrongly optimized out when inside a conditional Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm Assignee: unassigned at gcc dot gnu.org Reporter: Jeremie.Detrey at loria dot fr Created attachment 31050 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31050&action=edit Minimal example to reproduce the bug. When compiling the attached example with GCC 4.8.1 (on an x86_64 ArchLinux) using -O2 optimization, the `else' branch of the conditional in foo() is optimized out: GCC only generates code for the first branch, and does not test whether the value of `n' is zero or not. This can be seen in the following assembly output: $ gcc -O2 -S bug.c -o- .file "bug.c" .text .p2align 4,,15 .globl foo .type foo, @function foo: .LFB1: .cfi_startproc #APP # 4 "bug.c" 1 movq $42, %rdx movq %rdx, %rax # 0 "" 2 #NO_APP movq %rax, (%rsi) ret .cfi_endproc .LFE1: .size foo, .-foo .ident "GCC: (GNU) 4.8.1" .section .note.GNU-stack,"",@progbits This bug does not appear when compiling with GCC 4.7.3 (on an x86_64 Ubuntu 13.04, also with -O2 optimization): the two branches are generated, and the test on `n' is performed to select which branch to jump to: $ gcc -O2 -S bug.c -o- .file "bug.c" .text .p2align 4,,15 .globl foo .type foo, @function foo: .LFB1: .cfi_startproc testl %edi, %edi je .L5 #APP # 4 "bug.c" 1 movq $42, %rcx movq %rcx, %rax # 0 "" 2 #NO_APP movq %rax, (%rdx) ret .p2align 4,,10 .p2align 3 .L5: #APP # 4 "bug.c" 1 movq $42, %rdx movq %rdx, %rax # 0 "" 2 #NO_APP movq %rax, (%rsi) ret .cfi_endproc .LFE1: .size foo, .-foo .ident "GCC: (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3" .section .note.GNU-stack,"",@progbits This bug disappears (in GCC 4.8.1) when either declaring the inline asm block as `volatile', or removing the intermediate variable `t' and assigning 42 directly to `%[r]'.