This is an archive of the discontinued LLVM Phabricator instance.

[TBAA] Vector types should (only) alias with their element types
AbandonedPublic

Authored by hfinkel on Apr 19 2017, 5:14 PM.

Details

Summary

Currently, all of our builtin vector types are equivalent to char for TBAA purposes. It would be useful to make this less conservative. This patch makes vector types equivalent to their element types for type-aliasing purposes. I think it's common for programmers to assume that they can cast freely between the vector types and the scalar types (so long as they're being sufficiently careful about alignments), and we should certainly preserve that model. Given that we assume that int* and float* don't alias, I don't think we need to assume that int* and vec_of_float* alias or vec_of_int* and vec_of_float* alias.

The cases I've seen where I know this would be helpful involve integral scalar pointers and floating-point vector pointers, so I'm generalizing a bit here. If this would break too much code, one option is fall back to doing this only for floating-point types. That having been said, I know that it is common on some platforms to case between floating-point vectors and integer vectors in order to implement operations like fabs, and maybe that makes this untenable on those platforms?

Thoughts?

Diff Detail

Event Timeline

hfinkel created this revision.Apr 19 2017, 5:14 PM
hfinkel abandoned this revision.Apr 19 2017, 8:52 PM

@rjmccall said, on this topic, in D31885:

The root problem there is that the design of vector types and vector interfaces is generally quite bad; you cannot rely on things like vectors being stored with an appropriate element type for whatever value the user is actually trying to work with.

For example, Clang's xmmintrin.h specifies that m128 is a vector of 4 ints. How confident are you that that type is never used to store a vector of 4 floats? Keep in mind that the compiler allows m128 to freely implicitly convert to __v4sf.

And I think he's right; we probably can't do this in general. vector types really are just bags of bits on many platforms ;)