vectors of i1 and vectors x86 long double don't work
| Bugzilla Link | 1784 |
| Version | trunk |
| OS | Linux |
| Blocks | llvm/llvm-bugzilla-archive#31265 llvm/llvm-bugzilla-archive#3037 llvm/llvm-bugzilla-archive#3352 llvm/llvm-bugzilla-archive#7303 |
| Reporter | LLVM Bugzilla Contributor |
| CC | @asl,@hfinkel,@RKSimon,@sunfishcode,@darkbuck,@JonPsson,@kaomoneus,@trenouf,@Nuullll |
Extended Description
I noticed that a lot of the vector code assumes that there is no padding between vector elements. For example, the size is assumed to be the primitive size of the element times the number of elements. However for x86 long double the primitive size is 80 bits while elements will be spaced by 96/128 bits (depending on the os) in order to maintain alignment. There's a similar problem for vectors of apints.
mentioned in issue llvm/llvm-bugzilla-archive#8512
mentioned in issue llvm/llvm-bugzilla-archive#7303
mentioned in issue llvm/llvm-bugzilla-archive#6204
mentioned in issue llvm/llvm-bugzilla-archive#3451
mentioned in issue llvm/llvm-bugzilla-archive#34405
mentioned in issue llvm/llvm-bugzilla-archive#3434
mentioned in issue llvm/llvm-bugzilla-archive#3352
mentioned in issue llvm/llvm-bugzilla-archive#31265
mentioned in issue llvm/llvm-bugzilla-archive#3037
here my thoughts, GEP calculates the pointer address based on the data layout of the specified type. vector type is explicitly specified in the data layout of target and should not be assumed to be derived from corresponding scalar type, e.g. <8 x i1> from i1. The other point is not state very clearly in LLVM lang ref is that alignment (specified in bits) is always specified in unit of BYTE. That constrain is only stated for the natural stack alignment. But, we should assume that all alignment. In other word, GEP only calculates the pointer address in unit of BYTE.
Back to your specific issue, I agreed with that your frontend should not generated GEP into vector of i1. Instead, it should generate that in 2 steps of extraction of the corresponding bit following the vector load.
I have been thinking about my GEP issue some more.
On my target (which has typical byte-addressable memory and 64 bit pointers), what does a GEP into a vector of i1 mean? If you allow it, it surely means that any pointer to i1 might (or might not) be the result of a GEP into vector of i1, and therefore needs to keep a bit offset as well as the byte address. My target certainly does not support that, and more generally I think LLVM assumes that a pointer to anything (with a particular address space) is always the same size, whatever type it points to.
So my frontend should not be generating GEP into vector of i1, because it is not representable on the target that it is targeting.
I guess that in itself does not make a GEP into vector of i1 illegal IR, as someone may want to implement a target where it does make sense. But it falls into a class of things that you can only use in IR if it makes sense on your target.
If someone did want to implement a target where it makes sense, that probably means bit addressable memory, which means that the assumptions in LLVM that a store size is an integral number of bytes would need to be fixed. But I guess this is unlikely to be needed.
Yes, I committed the handling for stores of vectors with non byte-sized elements, see https://reviews.llvm.org/D42100.
I think Uli and Eli had an interesting discussion there on Jan 30, taking up this very topic that I think you are concerned about.
To me, it seems that although (I think) there is no formal statement anywhere, their discussion seems to indicate the path to follow. I am thinking about exactly how a vector should be stored in memory on big/little endian machines, including non-byte sized elements.
Perhaps the optimization passes you mention can be extended, or at least learn to reject cases they can not handle?
Work is still progressing, although at a glacial pace - Jonas Paulsson has done some work recently for instance.
I have just come across this because I am using the SPIR-V frontend https://github.com/KhronosGroup/SPIRV-LLVM and I have a case where it generates a GEP into a vector of i1 in memory.
A lot of code assumes that vector of i1 is packed (as already noted here), but at least GVN and alias analysis cannot cope with the GEP because it is not to a byte boundary.
Given that this issue has been hanging around for 10 years and does not seem to have a resolution, should LLVM stop claiming to fully support vector of i1? I.e. should the spec and the verify pass say that vector of i1 is illegal, or say that vector of i1 is legal but you can't GEP into it, or something?
A strong use case for the bitpacked approach is Parabix software. Parabix
is a framework for high-performance text processing using the concept of parallel bit streams. In Parabix, bytestreams
One significant application of Parabix is the icgrep search application, which generally achieves GB/s regular expression search even with complex regular expressions.
We have workarounds, but bitpacked vectors of i1 would be ideal.
Making this a parent bug makes sense to me.
Shall we make this bug a parent bug for more concrete bugs due to the same issue but in different components. The issue raised in this bug is quite high level and covers much more code/design. Some bugs is root-caused in the same but the fix would be quite different and probably not in relevant components. Making this a parent bug will track all related/children bugs more easily.
*** Bug llvm/llvm-bugzilla-archive#15131 has been marked as a duplicate of this bug. ***
*** Bug llvm/llvm-bugzilla-archive#12650 has been marked as a duplicate of this bug. ***
*** Bug llvm/llvm-bugzilla-archive#11460 has been marked as a duplicate of this bug. ***