Is it possible to load a value into a vector register and broadcast it in LLVM? For example, for the following address %x %x = getelementptr inbounds %struct._Ray* %ray, i32 0, i32 0, i32 0 instead of loading the value at %x into a scalar register %0: %0 = load double* %x, align 4, !tbaa !0 I want to load it into a <2 x double> vector register %1 and make both of the two elements in %1 be the value at %x. I guess one way to do this is to make getelementptr return a <2 x i32>* address, where the two addresses in <2 X 32> are the same. But I don't know if it is possible to do this in LLVM. Any help would be appreciated. Best, Zhi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150504/395c0786/attachment.html>
The canonical way to do it would be to load into a scalar, and then broadcast the scalar using a shufflevector. Hopefully, the backend will be smart enough to match this as a single load+broadcast, if the platform has such an instruction. (The trick you’re suggesting with getelementptr will probably possible soon, now that gather intrinsics are being introduced, but it probably will create worse code, not better.) Michael From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of zhi chen Sent: Monday, May 04, 2015 10:59 To: LLVM Dev Subject: [LLVMdev] Load value and broadcast in LLVM Is it possible to load a value into a vector register and broadcast it in LLVM? For example, for the following address %x %x = getelementptr inbounds %struct._Ray* %ray, i32 0, i32 0, i32 0 instead of loading the value at %x into a scalar register %0: %0 = load double* %x, align 4, !tbaa !0 I want to load it into a <2 x double> vector register %1 and make both of the two elements in %1 be the value at %x. I guess one way to do this is to make getelementptr return a <2 x i32>* address, where the two addresses in <2 X 32> are the same. But I don't know if it is possible to do this in LLVM. Any help would be appreciated. Best, Zhi --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150504/876a948f/attachment.html>
Hi Zhi, If I get your question correctly, Yes, you can do it by using the IRBuilder’s CreateVectorSplat() API. /// \brief Return a vector value that contains \arg V broadcasted to \p /// NumElts elements. Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") For your case, here the Value V will be your loaded value %0 and NumElts will be 2. So after %0 = load double* %x, align 4, !tbaa !0 you will get a sequence of LLVM-IR %1= insertelement <2 x double > %0, … %2= shufflevector <2 x double > %1, … %2 will be your desired value. Regards, Shahid From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of zhi chen Sent: Monday, May 04, 2015 1:29 PM To: LLVM Dev Subject: [LLVMdev] Load value and broadcast in LLVM Is it possible to load a value into a vector register and broadcast it in LLVM? For example, for the following address %x %x = getelementptr inbounds %struct._Ray* %ray, i32 0, i32 0, i32 0 instead of loading the value at %x into a scalar register %0: %0 = load double* %x, align 4, !tbaa !0 I want to load it into a <2 x double> vector register %1 and make both of the two elements in %1 be the value at %x. I guess one way to do this is to make getelementptr return a <2 x i32>* address, where the two addresses in <2 X 32> are the same. But I don't know if it is possible to do this in LLVM. Any help would be appreciated. Best, Zhi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150504/d337a813/attachment.html>
Hi Shahid, Thank you so much for your response. You suggested approach is what I am right now using. However, it seems that the overhead is a little bit high because we are introducing two more instructions. I was wondering if there was a cheaper way to do it. Best, Zhi On Mon, May 4, 2015 at 2:12 AM, Shahid, Asghar-ahmad < Asghar-ahmad.Shahid at amd.com> wrote:> Hi Zhi, > > > > If I get your question correctly, Yes, you can do it by using the > IRBuilder’s CreateVectorSplat() API. > > > > /// \brief Return a vector value that contains \arg V broadcasted to \p > > /// NumElts elements. > > Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name > "") > > > > For your case, here the Value V will be your loaded value %0 and NumElts > will be 2. > > > > So after %0 = load double* %x, align 4, !tbaa !0 > > you will get a sequence of LLVM-IR > > > > %1= insertelement <2 x double > %0, … > > %2= shufflevector <2 x double > %1, … > > > > %2 will be your desired value. > > > > Regards, > > Shahid > > > > *From:* llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] *On > Behalf Of *zhi chen > *Sent:* Monday, May 04, 2015 1:29 PM > *To:* LLVM Dev > *Subject:* [LLVMdev] Load value and broadcast in LLVM > > > > Is it possible to load a value into a vector register and broadcast it in > LLVM? > > > > For example, for the following address %x > > > > %x = getelementptr inbounds %struct._Ray* %ray, i32 0, i32 0, i32 0 > > > > instead of loading the value at %x into a scalar register %0: > > %0 = load double* %x, align 4, !tbaa !0 > > > > I want to load it into a <2 x double> vector register %1 and make both of > the two elements in %1 be the value at %x. > > > > I guess one way to do this is to make getelementptr return a <2 x i32>* > address, where the two addresses in <2 X 32> are the same. But I don't know > if it is possible to do this in LLVM. > > > > Any help would be appreciated. > > > > Best, > > Zhi > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150504/0985eb84/attachment.html>
Hi Kuperstein, It seemed that the backend would generate a VMOVAPD and a VPERMILPD. However, it also introduced many spills. I don't quite understand why. Best, Zhi On Mon, May 4, 2015 at 1:15 AM, Kuperstein, Michael M < michael.m.kuperstein at intel.com> wrote:> The canonical way to do it would be to load into a scalar, and then > broadcast the scalar using a shufflevector. > > Hopefully, the backend will be smart enough to match this as a single > load+broadcast, if the platform has such an instruction. > > > > (The trick you’re suggesting with getelementptr will probably possible > soon, now that gather intrinsics are being introduced, but it probably will > create worse code, not better.) > > > > Michael > > > > *From:* llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] *On > Behalf Of *zhi chen > *Sent:* Monday, May 04, 2015 10:59 > *To:* LLVM Dev > *Subject:* [LLVMdev] Load value and broadcast in LLVM > > > > Is it possible to load a value into a vector register and broadcast it in > LLVM? > > > > For example, for the following address %x > > > > %x = getelementptr inbounds %struct._Ray* %ray, i32 0, i32 0, i32 0 > > > > instead of loading the value at %x into a scalar register %0: > > %0 = load double* %x, align 4, !tbaa !0 > > > > I want to load it into a <2 x double> vector register %1 and make both of > the two elements in %1 be the value at %x. > > > > I guess one way to do this is to make getelementptr return a <2 x i32>* > address, where the two addresses in <2 X 32> are the same. But I don't know > if it is possible to do this in LLVM. > > > > Any help would be appreciated. > > > > Best, > > Zhi > > > > --------------------------------------------------------------------- > Intel Israel (74) Limited > > This e-mail and any attachments may contain confidential material for > the sole use of the intended recipient(s). Any review or distribution > by others is strictly prohibited. If you are not the intended > recipient, please contact the sender and delete all copies. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150504/66723669/attachment.html>
Seemingly Similar Threads
- [LLVMdev] Load value and broadcast in LLVM
- [LLVMdev] how can I create an SSE instrinsics sqrt?
- [LLVMdev] [RFC][PATCH] Adding absd/hadd/sad intrinsics
- [LLVMdev] Vectorization factor limitation in Loop Vectorizer
- [LLVMdev] how can I create an SSE instrinsics sqrt?