Matthieu Dubet
2013-Oct-11 17:27 UTC
[LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
Hi, I'm creating a small function in LLVM which gets as a parameter an i32* (this function is called from C code) . However I know that this pointer is actually a C array of size 10 ( int[10] ). How can I tell LLVM to consider this i32* as an <10 x i32> (and thus get the performance improvements thanks to SIMD ..etc..) ? Thanks, Matthieu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131011/0469d551/attachment.html>
Renato Golin
2013-Oct-11 17:40 UTC
[LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
On 11 October 2013 18:27, Matthieu Dubet <maattdd at gmail.com> wrote:> How can I tell LLVM to consider this i32* as an <10 x i32> (and thus get > the performance improvements thanks to SIMD ..etc..) ? >Hi Matthieu, You shouldn't need to do anything, the vectorizer should spot that for you, if the machine you're compiling to has support for vector instructions. Any kind of vector operations that you may want to hard-code will make it not work on anything other than the intrinsics/inline asm you're using, which is not a good idea. If your code didn't get vectorized, it's possible that it is not clear enough that that pointer is being iterated in a way that it's easy for the vectorizer to spot, so maybe you need to make it clearer, and that depends on the code in question. If you could share the code (or a similar example) with the list, people could help you spot the pattern and make it vectorize. cheers, --renato -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131011/6d4e2220/attachment.html>
Matthieu Dubet
2013-Oct-16 15:14 UTC
[LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
Hi, Thank you for the information, So I'm now keeping the array as a pointer (i32*) but the vectorizer doesn't vectorize it . I've pasted the function code before and after optimization (and the list of optimization that I have activated) in this Gist : https://gist.github.com/maattd/7008683 Some "weird" fact of my LLVM code : * all variables (even the one used for the loop condition) are pointers to memory allocated from the C world and passed to the LLVM functions as an argument * even with "opt->add(new llvm::DataLayout(*ee->getDataLayout())) ;" in the code, the module->dump() doesn't output neither data layout, nor triple target Both those points might confuse the vectorizer ? On Fri, Oct 11, 2013 at 1:40 PM, Renato Golin <renato.golin at linaro.org>wrote:> On 11 October 2013 18:27, Matthieu Dubet <maattdd at gmail.com> wrote: > >> How can I tell LLVM to consider this i32* as an <10 x i32> (and thus get >> the performance improvements thanks to SIMD ..etc..) ? >> > > Hi Matthieu, > > You shouldn't need to do anything, the vectorizer should spot that for > you, if the machine you're compiling to has support for vector > instructions. Any kind of vector operations that you may want to hard-code > will make it not work on anything other than the intrinsics/inline asm > you're using, which is not a good idea. > > If your code didn't get vectorized, it's possible that it is not clear > enough that that pointer is being iterated in a way that it's easy for the > vectorizer to spot, so maybe you need to make it clearer, and that depends > on the code in question. If you could share the code (or a similar example) > with the list, people could help you spot the pattern and make it vectorize. > > cheers, > --renato >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131016/545d0f5a/attachment.html>
James Courtier-Dutton
2013-Oct-17 08:53 UTC
[LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
If what you are saying is that you know the array of i32 will always be 10 entries, make the function use a constant limit=10 to the loop. I.e Make the loop limit a constant and not a variable. On 11 October 2013 18:27, Matthieu Dubet <maattdd at gmail.com> wrote:> Hi, > > I'm creating a small function in LLVM which gets as a parameter an i32* > (this function is called from C code) . > > However I know that this pointer is actually a C array of size 10 ( > int[10] ). > > How can I tell LLVM to consider this i32* as an <10 x i32> (and thus get > the performance improvements thanks to SIMD ..etc..) ? > > Thanks, > Matthieu > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131017/6ce2f480/attachment.html>
Matthieu Dubet
2013-Oct-17 14:15 UTC
[LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
Even if I know the size of the array, I'm not always iterating through it entirely so the loop count has to be a variable, but the vectorizer works fine even with a loop limit not constant when compiling C code from Clang for example so I should be able to do the same for this code .. (hopefully :) ) Matthieu On Thu, Oct 17, 2013 at 4:53 AM, James Courtier-Dutton < james.dutton at gmail.com> wrote:> If what you are saying is that you know the array of i32 will always be 10 > entries, make the function use a constant limit=10 to the loop. > I.e Make the loop limit a constant and not a variable. > > > > On 11 October 2013 18:27, Matthieu Dubet <maattdd at gmail.com> wrote: > >> Hi, >> >> I'm creating a small function in LLVM which gets as a parameter an i32* >> (this function is called from C code) . >> >> However I know that this pointer is actually a C array of size 10 ( >> int[10] ). >> >> How can I tell LLVM to consider this i32* as an <10 x i32> (and thus get >> the performance improvements thanks to SIMD ..etc..) ? >> >> Thanks, >> Matthieu >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131017/dbdadfa0/attachment.html>
Seemingly Similar Threads
- [LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
- [LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
- [LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
- [LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)
- [LLVMdev] Converting a i32 pointer to a vector of i32 ( C array to LLVM vector)