<div dir="ltr">That's pretty fundamental.<div><br></div><div><div>#define N 100</div><div>void pivot (int x[], int a[][N], int n, int k) {</div></div><div><br></div><div>a is a single block of memory, some unknown multiple of 400 bytes (100*sizeof(int)) long. When accessing it, the first index is multiplied by 400 and added to the second index multiplied by 4. This could be expressed by two successive GEPs or (a little better, and the reason for GEP) by a single combined GEP.</div><div><br></div><div>void pivot (int *x, int **a, int n, int k) {<br></div><div> </div><div>a is a block of memory containing an unknown number of pointers, with each pointer pointing at a block of memory containing an unknown number of ints. If you write a[x][y] then x is multiplied by sizeof(void*) and added to a. The pointer at that location is loaded, and added to y*sizeof(int) to get the final address. Two loads are unavoidable, and this can not be collapsed into a single GEP. GEP never accesses memory.</div><div><br></div><div>I don't know why GEP wouldn't be expressible by hardware. Obviously CPUs are hardware. Perhaps what you mean is that you need the result of the GEP to be resolved at compile time, which means that the original pointer must be the address of a static variable, and the indices must all be constant.</div><div><br></div><div>If you're trying to compile C to hardware, then you'd want an earlier pass to convert function locals from auto to static, and at the same time prove there is no recursion.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 3, 2017 at 9:06 AM, Anastasiya Ruzhanskaya via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I also looked at some examples and I noticed that these too function declaration result in totally different code:<br>#define N 100<br>void pivot (int x[], int a[][N], int n, int k) {<br><br><pre class="m_-7749262586344300711gmail-aLF-aPX-K0-aPE">void pivot (int *x, int **a, int n, int k) {<br></pre><pre class="m_-7749262586344300711gmail-aLF-aPX-K0-aPE">To access element if array a, in the second case I have to do a load at first , after getelementptr of the first dimension and then make getelementptr again : <br></pre><pre class="m_-7749262586344300711gmail-aLF-aPX-K0-aPE">getelementptr->load-><wbr>getelementptr.<br><br></pre><pre class="m_-7749262586344300711gmail-aLF-aPX-K0-aPE">In the first case there is only one getelementptr on the two dimensions simultaneously(getelementptr with three arguments) : getelementptr->load.<br><br></pre><pre class="m_-7749262586344300711gmail-aLF-aPX-K0-aPE">What is the difference? <br></pre></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-09-03 7:18 GMT+02:00 Anastasiya Ruzhanskaya <span dir="ltr"><<a href="mailto:anastasiya.ruzhanskaya@frtk.ru" target="_blank">anastasiya.ruzhanskaya@frtk.<wbr>ru</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So, I am trying to do smth like this. Basically, we are developing are own hls tool for fpga based on llvm. Getelementptr is not representable in hardware (as far as I understand, I am here a person , who deals with llvm mostly). The easiest case will be to derive the index and pass it to memory controller, which is connected to load and store instructions. However, when there is a getelementptr for structures - the things become too complicated to derive the offset (index). So, by now I am trying to understand what are rules for getelementptr in code, what can be it's successors , what can be it's predecessors in order to come to another solution.<br></div><div class="m_-7749262586344300711HOEnZb"><div class="m_-7749262586344300711h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-09-02 23:31 GMT+02:00 Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">No.<div>It would be helpful to understand what you are trying to accomplish overall, which may help people give you details about the best way to accomplish it.</div><div>For example, if you are trying to understand or recover array indexes from GEP's,  that is non-trivial.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-7749262586344300711m_76902852931930813h5">On Sat, Sep 2, 2017 at 3:53 AM, Anastasiya Ruzhanskaya via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-7749262586344300711m_76902852931930813h5"><div dir="ltr">Is there a way to set always a defined behavior here - for example that we will always one getelemntptr with complex index?<br></div><div class="m_-7749262586344300711m_76902852931930813m_8193756725356163238HOEnZb"><div class="m_-7749262586344300711m_76902852931930813m_8193756725356163238h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-09-02 12:53 GMT+02:00 Anastasiya Ruzhanskaya <span dir="ltr"><<a href="mailto:anastasiya.ruzhanskaya@frtk.ru" target="_blank">anastasiya.ruzhanskaya@frtk.r<wbr>u</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok, thank you. I have also one question about getelementptr. In different versions of clang I see that sometimes array[i][i] is preceded by two getelementptr instructions and sometimes only by one - with an already complex index.<br></div><div class="m_-7749262586344300711m_76902852931930813m_8193756725356163238m_-1642383242298597432HOEnZb"><div class="m_-7749262586344300711m_76902852931930813m_8193756725356163238m_-1642383242298597432h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-09-01 12:50 GMT+02:00 David Chisnall <span dir="ltr"><<a href="mailto:David.Chisnall@cl.cam.ac.uk" target="_blank">David.Chisnall@cl.cam.ac.uk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_-7749262586344300711m_76902852931930813m_8193756725356163238m_-1642383242298597432m_4485775279863739484HOEnZb"><div class="m_-7749262586344300711m_76902852931930813m_8193756725356163238m_-1642383242298597432m_4485775279863739484h5">On 1 Sep 2017, at 11:44, Anastasiya Ruzhanskaya via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hello,<br>
> I wonder if the getelementptr can have other successors than load, store in some other cases when I directly print or directly return the result. every time I would like to assign the result - it will have a load/store successor?<br>
> So, basically the overall question is to clarify the possible successors of getelementptr.<br>
<br>
</div></div>Any instruction that may take a pointer operand might be a user of a GEP.  For example, consider this C function:<br>
<br>
int x(struct S *s)<br>
{<br>
        y(&s->field);<br>
}<br>
<br>
Here, there will be a GEP to get the address of the field and then the user will be a call (or possibly invoke) instruction.<br>
<span class="m_-7749262586344300711m_76902852931930813m_8193756725356163238m_-1642383242298597432m_4485775279863739484HOEnZb"><font color="#888888"><br>
David<br>
<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br></div></div><span>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>