<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Hi Chuck!<DIV><BR class="khtml-block-placeholder"><DIV><DIV><DIV>On Jul 20, 2007, at 11:36 AM, Chuck Rose III wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"> <DIV class="Section1"><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">Hola LLVMers,<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">I’m looking to make use of the vectorization primitives in the Intel chip with the code we generate from LLVM and so I’ve started experimenting with it. What is the state of the machine code generated for vectors? In my tinkering, I seem to be getting some wonky machine instructions, but I’m most likely just doing something wrong and I’m hoping you can set me in the correct course.</SPAN></FONT></P></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV>Using SSE? The X86 backend is usually doing a pretty good job of it. <BR><BLOCKQUOTE type="cite"><DIV class="Section1"><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">My minimal function creates a float4 vector with a specified scalar in all the elements. It then extracts the third element and returns it. <O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">We are currently using the JIT and I’m currently synced to about a week after the 2.0 branch, so I’m admittedly stale by about a month.<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">In LLVM IR:<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">; ModuleID = 'test vectors'<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">define float @vSelect3(float %x) {<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">body:<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> %pv = alloca <4 x float> ; <<4 x float>*> [#uses=1]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> %v = load <4 x float>* %pv ; <<4 x float>> [#uses=1]</SPAN></FONT></P></DIV></BLOCKQUOTE><BLOCKQUOTE type="cite"><DIV class="Section1"><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> %v1 = insertelement <4 x float> %v, float %x, i32 0 ; <<4 x</SPAN></FONT></P></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV>You are allocating a chunk of memory on the stack then loading the undefined value back. I suppose this should be legal. So perhaps there is a codegen bug. With tot, I see sub $28, %esp. Maybe that's already fixed.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>But still, this is not what you want. You want to do this:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV> %v1 = insertelement <4 x float> undef, float %x, i32 0 ; <<4 x float>> [#uses=1] </DIV><DIV> %v2 = insertelement <4 x float> %v1, float %x, i32 1 ; <<4 x float>> [#uses=1] </DIV><DIV> %v3 = insertelement <4 x float> %v2, float %x, i32 2 ; <<4 xfloat>> [#uses=1] </DIV><DIV> %v4 = insertelement <4 x float> %v3, float %x, i32 3 </DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Starting from an undef and insert elements to form a vector.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Hope that helps.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Evan</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR><BLOCKQUOTE type="cite"><DIV class="Section1"><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">float>> [#uses=1]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> %v2 = insertelement <4 x float> %v1, float %x, i32 1 ; <<4 x<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">float>> [#uses=1]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> %v3 = insertelement <4 x float> %v2, float %x, i32 2 ; <<4 x<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">float>> [#uses=1]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> %v4 = insertelement <4 x float> %v3, float %x, i32 3 ; <<4 x<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">float>> [#uses=1]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> %s = extractelement <4 x float> %v4, i32 3 ; <float> [#uses<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">=1]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"> ret float %s<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">}<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">In Intel assembly, I get the following:<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80010 83ec20 sub esp,20h<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80013 f30f10442424 movss xmm0,dword ptr [esp+24h] </SPAN></FONT><FONT size="1" color="gray" face="Wingdings"><SPAN style="font-size: 8.0pt;font-family:Wingdings;color:gray">ß</SPAN></FONT><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";="" color:gray"=""> </SPAN></FONT><FONT size="1" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new""="">this loads x into the low float of xmm0<FONT color="gray"><SPAN style="color:gray"><O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80019 0f284c2404 movaps xmm1,xmmword ptr [esp+4] </SPAN></FONT><FONT size="1" color="gray" face="Wingdings"><SPAN style="font-size: 8.0pt;font-family:Wingdings;color:gray">ß</SPAN></FONT><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";="" color:gray"=""> </SPAN></FONT><FONT size="1" color="red" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:red"="">this seg faults because esp+4 isn’t 16-byte aligned<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" face="Courier New"><SPAN style="font-size:8.0pt; font-family:" courier="" new""="">What is that line trying to achieve? X is at [esp+24]. There weren’t any other parameters. <O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b8001e f30f10c8 movss xmm1,xmm0<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80022 8b442424 mov eax,dword ptr [esp+24h]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80026 660fc4c802 pinsrw xmm1,eax,2<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b8002b 89c1 mov ecx,eax<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b8002d c1e910 shr ecx,10h<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80030 660fc4c903 pinsrw xmm1,ecx,3<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80035 660fc4c804 pinsrw xmm1,eax,4<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b8003a 660fc4c905 pinsrw xmm1,ecx,5<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b8003f 660fc4c806 pinsrw xmm1,eax,6<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80044 660fc4c907 pinsrw xmm1,ecx,7<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80049 0fc6c903 shufps xmm1,xmm1,3<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b8004d f30f110c24 movss dword ptr [esp],xmm1<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80052 d90424 fld dword ptr [esp]<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80055 83c420 add esp,20h<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="1" color="gray" face="Courier New"><SPAN style="font-size:8.0pt;font-family:" courier="" new";color:gray"="">00000000`01b80058 c3 ret<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">The code used to generate and run the program was:<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/Module.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/DerivedTypes.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/Constants.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/Instructions.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/ModuleProvider.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/Analysis/Verifier.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/System/DynamicLibrary.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/ExecutionEngine/JIT.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/ExecutionEngine/Interpreter.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/ExecutionEngine/GenericValue.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon">"llvm/Support/ManagedStatic.h"<O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">#include</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="maroon"><SPAN style="color:maroon"><iostream><O:P></O:P></SPAN></FONT></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">using</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="blue"><SPAN style="color:blue">namespace</SPAN></FONT> llvm;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">Value* makeVector(Value* s, <FONT color="blue"><SPAN style="color:blue">unsigned</SPAN></FONT> <FONT color="blue"><SPAN style="color:blue">int</SPAN></FONT> dim, BasicBlock* basicBlock)<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">{<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> AllocaInst* pV = <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> AllocaInst(VectorType::get(Type::FloatTy,dim),<FONT color="maroon"><SPAN style="color:maroon">"pv"</SPAN></FONT>,basicBlock);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Value* v = <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> LoadInst(pV,<FONT color="maroon"><SPAN style="color:maroon">"v"</SPAN></FONT>,basicBlock);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="blue"><SPAN style="color:blue">for</SPAN></FONT> (<FONT color="blue"><SPAN style="color:blue">unsigned</SPAN></FONT> <FONT color="blue"><SPAN style="color:blue">int</SPAN></FONT> i = 0 ; i < dim ; ++i)<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> v = <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> InsertElementInst(v,s,i,<FONT color="maroon"><SPAN style="color:maroon">"v"</SPAN></FONT>,basicBlock);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="blue"><SPAN style="color:blue">return</SPAN></FONT> v;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">}<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">Function* generateVectorAndSelect(Module* pModule)<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">{<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> std::vector<Type <FONT color="blue"><SPAN style="color:blue">const</SPAN></FONT>*> params;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> params.push_back(Type::FloatTy);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> FunctionType* funcType = FunctionType::get(Type::FloatTy,params,NULL);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Function* func = cast<Function>(pModule->getOrInsertFunction(<FONT color="maroon"><SPAN style="color:maroon">"vSelect3"</SPAN></FONT>,funcType));<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> BasicBlock* basicBlock = <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> BasicBlock(<FONT color="maroon"><SPAN style="color:maroon">"body"</SPAN></FONT>,func);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Function::arg_iterator args = func->arg_begin();<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Argument* x = args;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> x->setName(<FONT color="maroon"><SPAN style="color:maroon">"x"</SPAN></FONT>);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Value* v1 = makeVector(x,4,basicBlock);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Value* s = <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> ExtractElementInst(v1,3,<FONT color="maroon"><SPAN style="color:maroon">"s"</SPAN></FONT>,basicBlock);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> ReturnInst(s,basicBlock);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="blue"><SPAN style="color:blue">return</SPAN></FONT> func;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">}<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">// modified from the fibonacci example<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" color="blue" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new";="" color:blue"="">int</SPAN></FONT><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> main(<FONT color="blue"><SPAN style="color:blue">int</SPAN></FONT> argc, <FONT color="blue"><SPAN style="color:blue">char</SPAN></FONT> **argv) <O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">{<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Module* pVectorModule = <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> Module(<FONT color="maroon"><SPAN style="color:maroon">"test vectors"</SPAN></FONT>);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> Function* pMain = generateVectorAndSelect(pVectorModule);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> pVectorModule->print(std::cout);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> GenericValue gv1, gv2, gvR;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> gv1.FloatVal = 2.0f;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> ExistingModuleProvider *pMP = <FONT color="blue"><SPAN style="color:blue">new</SPAN></FONT> ExistingModuleProvider(pVectorModule);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> pMP->getModule()->setDataLayout(<FONT color="maroon"><SPAN style="color:maroon">"e-p:32:32:32-i1:8:8:8-i8:8:8:8-i32:32:32:32-f32:32:32:32"</SPAN></FONT>);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> ExecutionEngine *pEE = ExecutionEngine::create(pMP, <FONT color="blue"><SPAN style="color:blue">false</SPAN></FONT>);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> std::vector<GenericValue> args;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> args.push_back(gv1);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> GenericValue result = pEE->runFunction(pMain, args);<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""> <FONT color="blue"><SPAN style="color:blue">return</SPAN></FONT> 0;<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""="">}<O:P></O:P></SPAN></FONT></P><P class="MsoNormal" style="text-autospace:none"><FONT size="2" face="Courier New"><SPAN style="font-size:10.0pt;font-family:" courier="" new""=""><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">Any help would be appreciated. <O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">. <O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">Thanks,<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">Chuck.</SPAN></FONT><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt;font-family:Arial"><O:P></O:P></SPAN></FONT></P> </DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">LLVM Developers mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</A> <SPAN class="Apple-converted-space"> </SPAN><A href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</A></DIV> </BLOCKQUOTE></DIV><BR></DIV></DIV></BODY></HTML>