<div dir="ltr">Hi Sam.<div><br></div><div>Thanks for the reply. This is not exactly what I was looking for. </div><div><br></div><div>Say I have a loop that looks like this:</div><div><br></div><div>sum = 0</div><div>for (i = 0; i < 4; i++)</div><div>  sum += (a[i] + b[i])</div><div><br></div><div>I would like a compiler to do the following:</div><div><br></div><div>vector.load vector.r0, addressOfA</div><div>vector.load vector.r1, addressOfB<br></div><div>vector.add vector.r0, vector.r0, vector.r1</div><div>sumreduce gpr.r0, vector.r0</div><div><br></div><div>Another scenario is adding all the elements of the array (this is probably a better example)</div><div>sum = 0</div><div>for (i = i; i < 4; i++)</div><div>  sum += a[i]</div><div><br></div><div>would be converted to </div><div>vector.load vector.r0, addressOfA</div><div>sumreduce gpr.r0, vector.r0</div><div><br></div><div><br></div><div>If you can assist with this, I would greatly appreciate it.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 17, 2016 at 2:57 AM, Sam Parker <span dir="ltr"><<a href="mailto:Sam.Parker@arm.com" target="_blank">Sam.Parker@arm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div>

<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Hi Rail,</p>
<p><br>
</p>
<p>If you want to reduce the elements of a vector to a scalar sum, isn't the source operand a vector already? If this is the case, you'll want to extract each element and then use the three adds, something like:</p>
<p><br>
</p>
<p>(add (add (add (extractelt VReg, 0), (extractelt VReg, 1)), (extractelt VReg, 2)), (extractelt VReg, 3))</p>
<p><br>
</p>
<p>cheers,</p>
<p>sam</p>
<p><br>
</p>
<div>
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Sam Parker</p>
<p>Graduate Engineer, Compilation Tools</p>
<p>Development Solutions Group</p>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%">
<div dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> on behalf of Rail Shafigulin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Sent:</b> 16 May 2016 22:56:25<br>
<b>To:</b> llvm-dev<br>
<b>Subject:</b> [llvm-dev] Struggling to define a simple instruction</font>
<div> </div>
</div><div><div class="h5">
<div>
<div dir="ltr">I'm trying to figure out how I can define and make LLVM target a simple instruction.
<div><br>
</div>
<div>The instruction is very simple, it adds all of the elements of the vector register. Lets' call it sum_reduce.</div>
<div><br>
</div>
<div>Defining a vector add was simple. All I had to do is to simply change the register type used by a regular add instruction and that was it. However I'm really struggling to define this new instruction.</div>
<div><br>
</div>
<div>Initially I thought that I would replace a chain of 3 adds with insert_element instructions, but that defeats the purpose of sum_reduce, since it would mean that I have to insert operators 4 times into a vector register and then add everything. This turns
 it into more instructions than the original chain of 3 adds. </div>
<div><br>
</div>
<div>I've also looked at X86 HADD instructions but also have difficulty understanding how to implement something similar to it in my target.</div>
<div>,</div>
<div>I've annoyed enough people on the LLVM IRC channel. And they have been really helpful, unfortunately I feel that if I ask more they'll stop answering completely :D</div>
<div><br>
</div>
<div>At this point I wouldn't mind some handholding.  I can provide more code if needed
</div>
<div><br>
</div>
<div>Any help on the issue is really appreciated.</div>
<div>
<div><br>
</div>
-- <br>
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>Rail Shafigulin<br>
</div>
Software Engineer <br>
Esencia Technologies<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div></div></div>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose,
 or store or copy the information in any medium. Thank you.
</div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Rail Shafigulin<br></div>Software Engineer <br>Esencia Technologies<br></div></div></div></div>
</div>