public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/58805] New: Inline assembly wrongly optimized out when inside a conditional
@ 2013-10-19 11:01 Jeremie.Detrey at loria dot fr
  2013-10-19 11:52 ` [Bug inline-asm/58805] " mikpelinux at gmail dot com
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: Jeremie.Detrey at loria dot fr @ 2013-10-19 11:01 UTC (permalink / raw)
  To: gcc-bugs

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]'.


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-10-24  8:47 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-19 11:01 [Bug inline-asm/58805] New: Inline assembly wrongly optimized out when inside a conditional Jeremie.Detrey at loria dot fr
2013-10-19 11:52 ` [Bug inline-asm/58805] " mikpelinux at gmail dot com
2013-10-19 18:02 ` [Bug inline-asm/58805] [4.8/4.9 Regression] " pinskia at gcc dot gnu.org
2013-10-19 19:15 ` mikpelinux at gmail dot com
2013-10-19 22:08 ` segher at gcc dot gnu.org
2013-10-19 22:39 ` pinskia at gcc dot gnu.org
2013-10-19 22:40 ` pinskia at gcc dot gnu.org
2013-10-19 22:59 ` segher at gcc dot gnu.org
2013-10-19 23:07 ` segher at gcc dot gnu.org
2013-10-21  9:11 ` [Bug tree-optimization/58805] " vries at gcc dot gnu.org
2013-10-21 10:14 ` vries at gcc dot gnu.org
2013-10-21 10:16 ` rguenth at gcc dot gnu.org
2013-10-21 12:24 ` vries at gcc dot gnu.org
2013-10-21 12:41 ` rguenth at gcc dot gnu.org
2013-10-21 14:43 ` vries at gcc dot gnu.org
2013-10-23 13:26 ` vries at gcc dot gnu.org
2013-10-23 19:17 ` vries at gcc dot gnu.org
2013-10-24  8:47 ` vries at gcc dot gnu.org

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).