Hi all, I'm trying to use LLVM to generate SIMD code at runtime (in particular Intel SSE). But I'm having a bit of trouble understanding how to create even the simplest function; adding two vectors of four single-precision floating-point elements. I can get it to add the elements one at a time but not using one vector instruction. All help much appreciated! Nicolas Capens -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080508/967e796c/attachment.html>
Hi Chris, Thanks for the advise, but I'm actually not trying to compile code from text. For now I'm just trying to construct the function directly. Think of it as the vector equivalent of the HowToUseJIT.cpp example. Cheers, -Nicolas -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Chris Lattner Sent: Thursday, 08 May, 2008 19:14 To: LLVM Developers Mailing List Subject: Re: [LLVMdev] Vector code On Thu, 8 May 2008, Nicolas Capens wrote:> I'm trying to use LLVM to generate SIMD code at runtime (in particularIntel> SSE). But I'm having a bit of trouble understanding how to create even the > simplest function; adding two vectors of four single-precision > floating-point elements. I can get it to add the elements one at a timebut> not using one vector instruction.I'd suggest writing code in C and seeing what llvm-gcc does with it. You can also look at (for example) llvm/test/CodeGen/X86/*.ll for many examples. -Chris -- http://nondot.org/sabre/ http://llvm.org/ _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On Thu, 8 May 2008, Nicolas Capens wrote:> I'm trying to use LLVM to generate SIMD code at runtime (in particular Intel > SSE). But I'm having a bit of trouble understanding how to create even the > simplest function; adding two vectors of four single-precision > floating-point elements. I can get it to add the elements one at a time but > not using one vector instruction.I'd suggest writing code in C and seeing what llvm-gcc does with it. You can also look at (for example) llvm/test/CodeGen/X86/*.ll for many examples. -Chris -- http://nondot.org/sabre/ http://llvm.org/
On Thu, May 8, 2008 8:24 am, Nicolas Capens wrote:> Hi all, > > > > I'm trying to use LLVM to generate SIMD code at runtime (in particular > Intel > SSE). But I'm having a bit of trouble understanding how to create even the > simplest function; adding two vectors of four single-precision > floating-point elements. I can get it to add the elements one at a time > but > not using one vector instruction.What is your target set to? If LLVM thinks it's targeting a processor that doesn't have SIMD instructions, it'll split vectors into scalars like this. Dan
Nicolas,> Thanks for the advise, but I'm actually not trying to compile code from > text. For now I'm just trying to construct the function directly. Think of > it as the vector equivalent of the HowToUseJIT.cpp example.llvm2cpp is your friend then. It's now a separate 'target' in llc. It will generate C++ code, which will construct provided IR. -- With best regards, Anton Korobeynikov. Faculty of Mathematics & Mechanics, Saint Petersburg State University.
Hi Dan, My CPU supports up to SSSE3, and I assume LLVM uses that as a target by default? I don't think that's the problem really, I'm just struggling to find the right functions/classes to create and manipulate vectors... Thank you, -Nicolas -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Dan Gohman Sent: Thursday, 08 May, 2008 19:47 To: LLVM Developers Mailing List Cc: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Vector code On Thu, May 8, 2008 8:24 am, Nicolas Capens wrote:> Hi all, > > > > I'm trying to use LLVM to generate SIMD code at runtime (in particular > Intel > SSE). But I'm having a bit of trouble understanding how to create even the > simplest function; adding two vectors of four single-precision > floating-point elements. I can get it to add the elements one at a time > but > not using one vector instruction.What is your target set to? If LLVM thinks it's targeting a processor that doesn't have SIMD instructions, it'll split vectors into scalars like this. Dan _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hi Anton, I assume that's the same as the online demo's "Show LLVM C++ API code" option (http://llvm.org/demo/)? I've tried that with a structure containing four floating-point components but it also appears to add them individually using extract/insert. Maybe I have to try an array of floats... Thanks, Anton -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Anton Korobeynikov Sent: Thursday, 08 May, 2008 19:59 To: LLVM Developers Mailing List Subject: Re: [LLVMdev] Vector code Nicolas,> Thanks for the advise, but I'm actually not trying to compile code from > text. For now I'm just trying to construct the function directly. Think of > it as the vector equivalent of the HowToUseJIT.cpp example.llvm2cpp is your friend then. It's now a separate 'target' in llc. It will generate C++ code, which will construct provided IR. -- With best regards, Anton Korobeynikov. Faculty of Mathematics & Mechanics, Saint Petersburg State University. _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
From the cellspu's test harnesses: define <4 x float> @fp_add_vec(<4 x float> %arg1, <4 x float> %arg2) { %A = add <4 x float> %arg1, %arg2 ret <4 x float> %A } It's a simple vector add for two v4f32 quantities. There are things you need to do in order to make the optimizer not optimize, e.g.: v4f32 fp_add_vec(v4f32 arg1, v4f32 arg2) { return arg1 + arg2; } Hope this helps. -scooter Nicolas Capens wrote:> > Hi all, > > I’m trying to use LLVM to generate SIMD code at runtime (in particular > Intel SSE). But I’m having a bit of trouble understanding how to > create even the simplest function; adding two vectors of four > single-precision floating-point elements. I can get it to add the > elements one at a time but not using one vector instruction. > > All help much appreciated! > > Nicolas Capens > > ------------------------------------------------------------------------ > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >