Andrew Booker
2011-Dec-14 15:06 UTC
[LLVMdev] extractvalue and insertvalue on vector types
Hi, I'm working with some hand-written LLVM IR which llvm-as doesn't like, giving me the error "Invalid indices for extractvalue". However, as far as I can tell, the code is valid according to the Language Reference Manual. A cut-down example of the kind of code in question is: %struct.s = type {i32,i32,<2 x i32>} define void @entry(i32* %out) { %1 = extractvalue %struct.s {i32 1, i32 2, <2 x i32> <i32 3, i32 4>}, 0 %2 = extractvalue %struct.s {i32 1, i32 2, <2 x i32> <i32 3, i32 4>}, 1 %3 = extractvalue %struct.s {i32 1, i32 2, <2 x i32> <i32 3, i32 4>}, 2, 0 %4 = extractvalue %struct.s {i32 1, i32 2, <2 x i32> <i32 3, i32 4>}, 2, 1 %5 = add i32 %1, %2 %6 = add i32 %5, %3 %7 = add i32 %6, %4 store i32 %7, i32* %out ret void } The error I quoted above is reported when llvm-as is trying to read the %3 line, accessing the first component of the <2 x i32> vector inside the struct. If I change the code such that the structure is defined with a 2-element array instead of a 2-element vector: %struct.s = type {i32,i32,[2 x i32]} then llvm-as does not report an error, hence why I believe the problem is specific to accessing vector components. According to the Language Reference Manual, I should be able to access vector components with extractvalue: "The 'extractvalue' instruction extracts the value of a member field from an aggregate value", and "Aggregate Types are a subset of derived types that can contain multiple member types. Arrays, structs and vectors are aggregate types". Also: "The operands [to extractvalue] are constant indices to specify which value to extract in a similar manner as indices in a 'getelementptr' instruction", and "subsequent types [indexed by getelementptr] can be arrays, vectors, and structs." Any pointers as to what I'm doing wrong, or is this a mistake in the reference manual? I could believe that you're not meant to use extractvalue and insertvalue on vector types, since that would seem to duplicate the behaviour of extractelement and insertelement, but, at the moment, the manual says that it's allowed. Andrew
Hi Andrew,> If I change the code such that the structure is defined with a > 2-element array instead of a 2-element vector: > %struct.s = type {i32,i32,[2 x i32]} > then llvm-as does not report an error, hence why I believe the problem > is specific to accessing vector components.correct, extractvalue doesn't work on vectors, you need to use to use extractelement for them.> According to the Language Reference Manual, I should be able to access > vector components with extractvalue: > > "The 'extractvalue' instruction extracts the value of a member field > from an aggregate value", and "Aggregate Types are a subset of derived > types that can contain multiple member types. Arrays, structs and > vectors are aggregate types". > > Also: > "The operands [to extractvalue] are constant indices to specify which > value to extract in a similar manner as indices in a 'getelementptr' > instruction", and "subsequent types [indexed by getelementptr] can be > arrays, vectors, and structs."These are mistakes in the language ref. Ciao, Duncan.> Any pointers as to what I'm doing wrong, or is this a mistake in the > reference manual? I could believe that you're not meant to use > extractvalue and insertvalue on vector types, since that would seem to > duplicate the behaviour of extractelement and insertelement, but, at > the moment, the manual says that it's allowed. > > Andrew > > > > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Andrew Booker
2011-Dec-15 15:49 UTC
[LLVMdev] extractvalue and insertvalue on vector types
Duncan Sands wrote on 2011-12-14:> correct, extractvalue doesn't work on vectors, you need to use to > use extractelement for them.Thanks for the clarification. I see that the language reference has already been updated to say that only arrays and structs are aggregate types, and that vectors aren't. I wonder whether it's also worth an explicit note in the documentation for extractvalue, in the section where it lists the differences between extractvalue indexing and getelementptr indexing? Perhaps adding a new bullet point that simply says "Indexing into vectors is not allowed". Andrew
Reasonably Related Threads
- [LLVMdev] extractvalue and insertvalue on vector types
- [LLVMdev] Extend SLPVectorizer to struct operations that are isomorphic to vector operations?
- Indices for extractvalue and insertvalue
- [LLVMdev] const indices of extractvalue
- [LLVMdev] SIMD instructions and memory alignment on X86