https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71383
Bug ID: 71383
Summary: Misoptimized branch with inline assembly code.
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: bmei at broadcom dot com
Target Milestone: ---
For the following example:
include <stdio.h>
static int a, b;
static void bar()
{
asm volatile ("" : : : "memory");
}
void foo ()
{
a = 0;
bar ();
if (a == 0)
printf ("HERE\n");
}
If compiles with:
~/work/install-x86/bin/gcc tst.c -O2 -S -fno-inline
The conditional printf becomes unconditional. if (a==0) is optimized away.
foo:
.LFB1:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
xorl %eax, %eax
movl $0, a(%rip)
call bar
movl $.LC0, %edi
addq $8, %rsp
.cfi_def_cfa_offset 8
jmp puts
.cfi_endproc
However, if we compile with
~/work/install-x86/bin/gcc tst.c -O2 -S and allow inlining, gcc produces
correct code.
foo:
.LFB12:
.cfi_startproc
movl $0, a(%rip)
movl a(%rip), %eax
testl %eax, %eax
je .L4
rep; ret
.p2align 4,,10
.p2align 3
.L4:
movl $.LC0, %edi
jmp puts
I guess it goes wrong in some of IPA passes.
My compiler is GCC: (GNU) 7.0.0 20160602 (experimental) [trunk revision 14336].
I can also reproduce this issue on our port of gcc 6.1.