Mill Computing, Inc. Forums The Mill Tools Compilers Loop compilation

  • Author
    Posts
  • Witold Baryluk
    Participant
    Post count: 33
    #3362 |

    Hi,

    If I have a code that does something like this (at bit more than extremely primitive trivial loop):

    
    extern int n;
    extern int* A1;
    
    int f(int x, int y) {
      int tmp1 = 0;
      int tmp2 = 0;
      for (int i = 0; i < n; i++) {
        int mytmp = A1[i] * i;
        tmp1 += mytmp * x;
        tmp2 += mytmp * x * i;
      }
      return tmp1 * tmp2 * y;
    }
    

    and assuming no unrolling and pipelining and other optimization, my understanding is that it will be separated into 3 EBBs:

    <init_ebb> % setup the belt with tmp1 and tmp2 for loop_ebb and epilog_ebb, but also with x and y.
    <loop_ebb> % carry stuff over, do computations, and at the end restore belt into proper shape for loop_ebb reentry or epilog_ebb
    <epilog_ebb> % trivial consume stuff from the belt and return

    with loop_ebb needing to carry over the tmp1, tmp2, x, y, even if it temporarily used belt to store some additional value, or didn’t even use y.

    My question: What kind of operation would be used at the exit of the loop_ebb to jump again to loop_ebb or epilog_ebb ? how the belt would be configured for loop_ebb, so the epilog_ebb can see properly all used variables? I also guess that the n, usually will be loaded from memory once by init_ebb, and put on belt too, and preserved across calls to loop_ebb and epilog_ebb, and ultimately ignored by epilog_ebb.

    I understand that first step would be to convert this into SSA form, but at the same time, it feels the end result will look like a tail call style looping from functional languages, and the issue of moving arguments on belt to be on the same positions as before (so next EBB works correctly), could lead to a big per loop iteration overhead (especially if there is a lot of carry over values, even if they are not used or updated in the loop itself, like ‘y’ above.).

    A discussion, or output of the current Mill conAsm could help too. 🙂

    Thanks!

    • This topic was modified 5 years, 11 months ago by  Witold Baryluk. Reason: Formating
    • This topic was modified 5 years, 11 months ago by  Witold Baryluk.

You must be logged in to reply to this topic.