[Bug c/66777] New: faggressive-loop-optimizations behavior.
dongkyun.s at samsung dot com
gcc-bugzilla@gcc.gnu.org
Mon Jul 6 11:26:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66777
Bug ID: 66777
Summary: faggressive-loop-optimizations behavior.
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: dongkyun.s at samsung dot com
Target Milestone: ---
The following program seems to have optimized with -O2
(-faggressive-loop-optimizations).
#include <stdio.h>
int main(void)
{
int a[5];
int i;
for (i = 0; a[i] && i < 5; i++)
printf("%d\n", a[i]);
return 0;
}
1) .s with -O2 option (-faggressive-loop-optimizations)
...
.L4
r02 mo3w r0, #:lower16:.LC0
movt r0, #:upper16:.LC0
bl printf
ldr r1, [r4, #4]!
cmp r1, #0 // a[i]
bne .L4
...
2) .s without -On option (-fno-aggressive-loop-optimizations)
...
.L4
...
ldr r2, [fp, #-8]
mvn r3, #23
mov r2, r2, asl #2
sub r1, fp, #4
add r2, r2, r1
add r3, r2, r3
ldr r3, [r3, #0]
cmp r3, #0 // a[i]
beq .L3
ldr r3, [fp, #-8]
cmp r3, #4 // i < 5
ble .L4
.L3
...
< -faggressive-loop-optimizations >
This assumes that loop code does not invoke undefined behavior by for example
causing signed integer overflows or out-of-bound array accesses. The bounds for
the number of iterations of a loop are used to guide loop unrolling and peeling
and loop exit test optimizations. This option is enabled by default.
The problem with 1) option (-faggressive-loop-optimizations) is that the
developer cannot recognize the program have bug which can cause NULL pointer
exception.
Is there some warning option releated to this optimization ?
More information about the Gcc-bugs
mailing list