You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
staticboolany_of_impl(int* first, int* last, int num)
{
for (; first != last; ++first) {
if (*first == num)
returntrue;
}
returnfalse;
}
boolsquare(int num) {
int x[] = {1,2,3};
returnany_of_impl(x, x+3, num);
}
boolcube(int num) {
return num==1 || num==2 || num==3;
}
-O2 or -O3
Expected: Same asm for both
Actual:
square(int):
cmp edi, 1
sete cl
add edi, -2
test edi, -2
sete al
or al, cl
ret
cube(int):
dec edi
cmp edi, 3
setb al
ret
The expected result shows up on pretty much any simplification of the input, including moving the +3 to the callee, or changing both functions' return type to int. Feels like some optimizer passes are running in wrong order and confusing each other.
This seems to be a phase-ordering problem. We need another InstCombine run to cleanup after late SimplifyCFG pass converts the icmp chain into a range check + select. Or just handle this case in SimplifyCFG.
-O2 or -O3
Expected: Same asm for both
Actual:
The expected result shows up on pretty much any simplification of the input, including moving the +3 to the callee, or changing both functions' return type to int. Feels like some optimizer passes are running in wrong order and confusing each other.
https://godbolt.org/z/88938fP3d
Originally found via a std::ranges::any_of call, hence the function name. It turned into std::find when I reduced it. https://godbolt.org/z/GjsE3vEK4
The text was updated successfully, but these errors were encountered: