This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/67449] New: Branch elimination problem on x86
- From: "lh_mouse at 126 dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 04 Sep 2015 10:26:49 +0000
- Subject: [Bug rtl-optimization/67449] New: Branch elimination problem on x86
- Auto-submitted: auto-generated
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>