https://bugs.llvm.org/show_bug.cgi?id=34538
Bug ID: 34538
Summary: Failure to optimize range loops
Product: libraries
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Loop Optimizer
Assignee: unassignedb...@nondot.org
Reporter: gonzalob...@gmail.com
CC: llvm-bugs@lists.llvm.org
Given the following modern C++ range-like code using optionals (see it here in
action: https://godbolt.org/g/Lz1xNK):
struct range { int start; int end; };
struct option { int ret; int tag; };
inline
option next(range *range) {
if (range->start < range->end) {
int n = range->start;
range->start++;
option o{n, 1};
return o;
} else {
option o{0, 0};
return o;
}
}
int loop() {
range rng = {0, 100};
for(;;) {
option o = next(&rng);
if (o.tag) {
// nothing
} else {
break;
}
}
return 0;
}
GCC generates the following assembly:
loop():
xor eax, eax
ret
while clang fails to optimize the loop, generating:
loop(): # @loop()
xor eax, eax
.LBB0_1: # =>This Inner Loop Header: Depth=1
xor ecx, ecx
cmp eax, 100
setl cl
add ecx, eax
cmp eax, 100
mov eax, ecx
jl .LBB0_1
xor eax, eax
ret
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs