3 ms·
Rust doesn't have null pointers, so I see no language-level reason why that wouldn't vectorize. LLVM's vectorizer tends to be pretty brittle, so probably tweaki
by pcwalton 12y ago
Rust doesn't have null pointers, so I see no language-level reason why that wouldn't vectorize. LLVM's vectorizer tends to be pretty brittle, so probably tweaking the generated IR a bit would cause us to vectorize. Feel free to file an issue if you have time :)
- heinrich5991 12y agoThat might still be the case. IIRC I read somewhere that when the iterator code gets inlined, the non-nullness of the pointer gets lost, as the iterators internally use raw pointers (which can be null in Rust).
- pcwalton 12y agoYeah, nonnull is only allowed on parameters in LLVM IR, so it gets lost post-inlining. I'm pretty sure it's LLVM that is inserting those null checks, as we never do in the frontend (since safe pointers are not null in Rust, and unsafe pointers are never checked for null since they're unsafe).
- gliptic 12y agoDoesn't it insert None checks for Option<&u32> (because of zip)? LLVM probably doesn't figure out that they'll never be NULL.
- pcwalton 12y agoYeah, that's probably it. (The compiler isn't inserting the checks, but rather the libraries are.) The vectorizer can't safely vectorize that code without changing when failure occurs if the vectors are different lengths. Perhaps the best thing to do is to change zip, or add a new parameter to zip, to allow it to "chunk" its inputs and thereby enable vectorization. Or we could have a special type that encapsulates two or more vectors and checks up front that they're the same length, so that zip can then assume that they're the same length. It also might be possible to add an optimization to LLVM to have it figure out that the vectors are the same length.
- AaronFriel 12y agoIf zip is following the 'functional' definition, it should only return a list of the length of the shorter of the two inputs. In Haskell: zip :: [a] -> [b] -> [(a, b)] Not: zip :: [a] -> [b] -> [(Maybe a, Maybe b)] If you want to allow processing a sequence of tails, you could have: zipWithTail :: [a] -> [b] -> ([(a, b)], Either [a] [b]) Which would return a list of pairs and a list of either the tail of the first or the second input, whichever was longer.
- pcwalton 12y agoIt is following that definition, but the issue is that it's built on iterators, which are of unknown length. Haskell would have effectively the same checks if built on lists because of the way lazy thunks work.
- pbsd 12y agoWell Rust is checking for null pointers at the assembly level: http://goo.gl/eh2aqc http://goo.gl/eh2aqc (lines 22--27).
- pcwalton 12y agoBlech. I'm pretty sure LLVM, not the frontend, is inserting those null checks for some reason.
- kzrdude 12y agoThe slice iterator yields `Option<&T>`, the None variant is represented by a null pointer. That's probably the null check.
- dbaupp 12y agoThis is https://github.com/mozilla/rust/issues/11751 https://github.com/mozilla/rust/issues/11751: LLVM doesn't understand (non)null pointers enough.