What I want to do is to change the pInst from : 2%= load double* %1, align 8 to 2% = load < 2 x double>* %1, align 16, where <2 x double> should be two double identical double values that is same as the one in the previous instruction Instruction* ScalarToVectorLoad(Instruction* pInst) { Value *loadValue = pInst->getOperand(0); Instruction *newLoad; //this one should be 2% = load < 2 x double>* %1 BitCastInst *scalarToVector = new BitCastInst(loadValue, VectorType::get(Type::getDoubleTy(currF->getContext()), 2), "vectorizedLoad", pInst); newLoad = new LoadInst(); //to be implemented... return newLoad; } On Wed, Apr 15, 2015 at 1:03 PM, mats petersson <mats at planetcatfish.com> wrote:> Create a type that is a "vector (array) of 2 double", and then a > pointer to that. Now use bitcast your on double pointer to that > pointer type you've created, and then create a load... > > If you need more help, it would help if you post the code you are working > on... > > -- > Mats > > On 15 April 2015 at 19:51, zhi chen <zchenhn at gmail.com> wrote: > > How can I write code to generate IR for: > > %2 = bitcast double* %1 to <2 x double>*. > > %3 = load <2 x double>* %2, align 16 > > Basically, it is similar to x86 _mm_load_pd1 intrinsics. > > > > Thanks, > > Zhi > > > > _______________________________________________ > > 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/20150415/ca466b4e/attachment.html>
mats petersson
2015-Apr-15 21:13 UTC
[LLVMdev] How to do bitcast for double to <2 x double>
So, you need to bitcast `pinst` to a pointer to Vector of double, since it (I hope for your sake) is a pointer to integer. What you are trying to do is bitcast a pointer into a vector, which probably will lead to an assert or "bad code that doesn't work". -- Mats On 15 April 2015 at 21:57, zhi chen <zchenhn at gmail.com> wrote:> What I want to do is to change the pInst from : 2%= load double* %1, align 8 > to 2% = load < 2 x double>* %1, align 16, where <2 x double> should be two > double identical double values that is same as the one in the previous > instruction > > Instruction* ScalarToVectorLoad(Instruction* pInst) { > Value *loadValue = pInst->getOperand(0); > Instruction *newLoad; //this one should be 2% = load < 2 x double>* %1 > > BitCastInst *scalarToVector = new BitCastInst(loadValue, > VectorType::get(Type::getDoubleTy(currF->getContext()), 2), > "vectorizedLoad", pInst); > newLoad = new LoadInst(); //to be implemented... > return newLoad; > } > > On Wed, Apr 15, 2015 at 1:03 PM, mats petersson <mats at planetcatfish.com> > wrote: >> >> Create a type that is a "vector (array) of 2 double", and then a >> pointer to that. Now use bitcast your on double pointer to that >> pointer type you've created, and then create a load... >> >> If you need more help, it would help if you post the code you are working >> on... >> >> -- >> Mats >> >> On 15 April 2015 at 19:51, zhi chen <zchenhn at gmail.com> wrote: >> > How can I write code to generate IR for: >> > %2 = bitcast double* %1 to <2 x double>*. >> > %3 = load <2 x double>* %2, align 16 >> > Basically, it is similar to x86 _mm_load_pd1 intrinsics. >> > >> > Thanks, >> > Zhi >> > >> > _______________________________________________ >> > LLVM Developers mailing list >> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > > >
Thanks Mats. Yes, it currently leads to "Illegal BitCast". Can I change the pInst directly to generate the code I want? On Wed, Apr 15, 2015 at 2:13 PM, mats petersson <mats at planetcatfish.com> wrote:> So, you need to bitcast `pinst` to a pointer to Vector of double, > since it (I hope for your sake) is a pointer to integer. What you are > trying to do is bitcast a pointer into a vector, which probably will > lead to an assert or "bad code that doesn't work". > > -- > Mats > > On 15 April 2015 at 21:57, zhi chen <zchenhn at gmail.com> wrote: > > What I want to do is to change the pInst from : 2%= load double* %1, > align 8 > > to 2% = load < 2 x double>* %1, align 16, where <2 x double> should be > two > > double identical double values that is same as the one in the previous > > instruction > > > > Instruction* ScalarToVectorLoad(Instruction* pInst) { > > Value *loadValue = pInst->getOperand(0); > > Instruction *newLoad; //this one should be 2% = load < 2 x double>* > %1 > > > > BitCastInst *scalarToVector = new BitCastInst(loadValue, > > VectorType::get(Type::getDoubleTy(currF->getContext()), 2), > > "vectorizedLoad", pInst); > > newLoad = new LoadInst(); //to be implemented... > > return newLoad; > > } > > > > On Wed, Apr 15, 2015 at 1:03 PM, mats petersson <mats at planetcatfish.com> > > wrote: > >> > >> Create a type that is a "vector (array) of 2 double", and then a > >> pointer to that. Now use bitcast your on double pointer to that > >> pointer type you've created, and then create a load... > >> > >> If you need more help, it would help if you post the code you are > working > >> on... > >> > >> -- > >> Mats > >> > >> On 15 April 2015 at 19:51, zhi chen <zchenhn at gmail.com> wrote: > >> > How can I write code to generate IR for: > >> > %2 = bitcast double* %1 to <2 x double>*. > >> > %3 = load <2 x double>* %2, align 16 > >> > Basically, it is similar to x86 _mm_load_pd1 intrinsics. > >> > > >> > Thanks, > >> > Zhi > >> > > >> > _______________________________________________ > >> > 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/20150415/a9dbb878/attachment.html>