llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

vectors of i1 and vectors x86 long double don't work

Open llvmbot opened this issue 19 years ago • 40 comments

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.

llvmbot avatar Nov 09 '07 10:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#8512

llvmbot avatar Nov 27 '21 06:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#7303

llvmbot avatar Nov 27 '21 05:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#6204

llvmbot avatar Nov 27 '21 05:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#3451

llvmbot avatar Nov 26 '21 23:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#34405

llvmbot avatar Nov 26 '21 23:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#3434

llvmbot avatar Nov 26 '21 23:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#3352

llvmbot avatar Nov 26 '21 23:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#31265

RKSimon avatar Nov 26 '21 22:11 RKSimon

mentioned in issue llvm/llvm-bugzilla-archive#3037

llvmbot avatar Nov 26 '21 22:11 llvmbot

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.

darkbuck avatar Mar 10 '18 10:03 darkbuck

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.

trenouf avatar Mar 10 '18 09:03 trenouf

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?

JonPsson avatar Mar 08 '18 13:03 JonPsson

Work is still progressing, although at a glacial pace - Jonas Paulsson has done some work recently for instance.

RKSimon avatar Mar 08 '18 13:03 RKSimon

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?

trenouf avatar Mar 08 '18 09:03 trenouf

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 are transformed to parallel arrays of bit streams . The streams are then processed 256 elements at a time using the 256-bit registers of AVX2, for example.

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.

llvmbot avatar Aug 16 '16 00:08 llvmbot

Making this a parent bug makes sense to me.

llvmbot avatar Mar 01 '13 10:03 llvmbot

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.

darkbuck avatar Mar 01 '13 07:03 darkbuck

*** Bug llvm/llvm-bugzilla-archive#15131 has been marked as a duplicate of this bug. ***

llvmbot avatar Feb 20 '13 19:02 llvmbot

*** Bug llvm/llvm-bugzilla-archive#12650 has been marked as a duplicate of this bug. ***

llvmbot avatar May 05 '12 21:05 llvmbot

*** Bug llvm/llvm-bugzilla-archive#11460 has been marked as a duplicate of this bug. ***

llvmbot avatar Dec 01 '11 16:12 llvmbot