[Bug tree-optimization/84648] New: Missed optimization : loop not removed.
cassio.neri at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Mar 1 14:34:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84648
Bug ID: 84648
Summary: Missed optimization : loop not removed.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: cassio.neri at gmail dot com
Target Milestone: ---
The loop below is not eliminated:
int main() {
for (unsigned i = 0; i < (1u << 31); ++i) {
}
return 0;
}
Compiled with -O3:
main:
xor eax, eax
.L2:
add eax, 1
jns .L2
xor eax, eax
ret
The loop is removed for other bounds, e.g. (1u << 31) + 1 or (1u << 31) - 1, or
when < is replaced with <=.
Allow me to make a guess of the underlying problem: The optimization that uses
jns to detect when i reaches (10...0)_2 ends up by blocking the other
optimization that eliminates the loop altoghether.
Same issue when using unsigned long long and (1ull << 63).
FWIW: clang has the same issue (in C but not in C++).
More information about the Gcc-bugs
mailing list