-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] The representation of bounded iterators inhibits Clang vectorization #108600
Comments
Interesting. If you write a much simpler loop, it vectorizes just fine:
Looking at the generated code, I think the lack of vectorization is a red herring. Notice how there are branches inside the loop that jump to a I think the issue is that the compiler can't tell that That gives an even more minimized version: The compiler should delete the safety check, but it's still emitting one. Looks like it's checking for the length being negative, so we might have another variation of #78784? Not positive.
Hmm. #101372 revealed an issue where the compiler's pointer reasoning is worse than the compiler's integer reasoning due to some alignment issues. Perhaps something similar is happening? |
(@danakj FYI) |
Actually my last minimization might not be correct. I think that's a different issue, which is that
One way or another, there seem to be a lot of gaps in the compiler's ability to do bounds-related analysis! :-) |
With test code like this:
Without bounded iterators, Clang vectorizes this code. When we enable bounded iterators though, Clang isn't able to vectorize anymore.
For information, the current representation of
__bounded_iter
is as follows:I played around with changing the representation of
__bounded_iter
to see if that could make any difference, and it looks like the following representation instead allows Clang to vectorize this code:Funnily enough, it seems that this representation leads to better code than the version that doesn't use bounded iterators!
Godbolt with a pointer (status quo): https://godbolt.org/z/efa77anqK
Godbolt with the index: https://godbolt.org/z/f9n5zs8sv
The text was updated successfully, but these errors were encountered: