https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67449
Bug ID: 67449 Summary: Branch elimination problem on x86 Product: gcc Version: 4.9.3 Status: UNCONFIRMED Severity: minor Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- The following `do ... while` statement creates a loop with two branches: C code: <code> int a[10]; void next(int **pp){ (++*pp == a + 10) && (*pp = 0); } int main(){ for(int i = 0; i < 10; ++i){ a[i] = i; } int *p = a; do { __builtin_printf("element = %d\n", *p); next(&p); // __asm__(""); } while(p); } </code> Assembly output: <code> L13: testl %ebx, %ebx je L6 ; one here. L4: movl (%ebx), %eax movl $LC1, (%esp) addl $4, %ebx movl %eax, 4(%esp) call _printf cmpl $_a+40, %ebx jne L13 ; another one here. L6: </code> But if we uncomment that empty __asm__ statement, the first branch vanishes: Assembly output: <code> L5: movl (%ebx), %eax movl $LC1, (%esp) addl $4, %ebx movl %eax, 4(%esp) call _printf cmpl $_a+40, %ebx cmove %esi, %ebx testl %ebx, %ebx ; the only one branch in this loop. jne L5 </code>