https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90089
Bug ID: 90089
Summary: Missing optimization, elimination of empty data
dependant loops
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
void * x;
void test(){ for(void * p = x; p; p=*(void**)p); }
With -O3 gives:
test():
mov rax, QWORD PTR x[rip]
test rax, rax
je .L1
.L3:
mov rax, QWORD PTR [rax]
test rax, rax
jne .L3
.L1:
ret
As you can see it currently traverses pointers even though it could be
optimized away.
6.8.2.2 Forward progress
The implementation may assume that any thread will eventually do one of the
following:
(1.1) terminate,
(1.2) make a call to a library I/O function,
(1.3) perform an access through a volatile glvalue, or
(1.4) perform a synchronization operation or an atomic operation.
[ Note: This is intended to allow compiler transformations such as removal of
empty loops, even when termination cannot be proven. — end note ]
MSVC and ICC performs this optimization.