systems-nuts / unifico

Compiler and build harness for heterogeneous-ISA binaries with the same stack layout.
3 stars 1 forks source link

[stackmaps] Live values in stack slots that do not exist in assembly #306

Closed blackgeorge-boom closed 10 months ago

blackgeorge-boom commented 10 months ago
int main(int argc, char *argv[])
{
  int i, j, k, it;

  double rnorm;

  firstrow = 0;
  lastrow  = NA-1;
  lastcol  = NA-1;

  printf(" Size: %11d\n", NA);

  naa = NA;
  nzz = NZ;

  //---------------------------------------------------------------------
  // set starting vector to (1, 1, .... 1)
  //---------------------------------------------------------------------
  for (i = 0; i < NA+1; i++) {
    x[i] = 1.0;
  }
  for (j = 0; j < lastcol - firstcol + 1; j++) {
    q[j] = 0.0;
    z[j] = 0.0;
    r[j] = 0.0;
    p[j] = 0.0;
  }

  for (it = 1; it <= 1; it++) {
    conj_grad(colidx, rowstr, x, z, a, p, q, r, &rnorm);
  }

  return 0;
}
make clean; make stackmaps-check -j10 OBJDUMP_FLAGS= OPT_LEVEL=-O1 TARGET_FUNC=main

WARNING: main: callsite 0, value locations 0/0 have different location offset or  different constant (-24 vs. -32)

No spills are shown in the actual assembly.

0000000000501020 main:
  501020:       sub sp, sp, #0x30
  501024:       str x19, [sp, #0x18]
  501028:       stp x29, x30, [sp, #0x20]
  50102c:       add x29, sp, #0x20
  501030:       adrp    x8, #0x300000
  501034:       mov w19, #0x1
  501038:       adrp    x0, #0x100000
  50103c:       mov w1, #0x24f8
  501040:       strb    w19, [x8]
  501044:       adrp    x8, #0x300000
  501048:       add x0, x0, #0x0
  50104c:       movk    w1, #0x1, lsl #16
  501050:       strb    w19, [x8, #0x4]
  501054:       bl  #0x1790 <printf>
...
blackgeorge-boom commented 10 months ago

Could it be that there is an optimization happening later that does not update the stackmaps?

blackgeorge-boom commented 10 months ago

The problem was that this code was passing %rnorm as a parameter to conj_grad, hence that stack slot was indeed a live value (%stack.0.rnorm), but we were never initializing it! That's why we couldn't see a store instruction in either of the assemblies, but there were these instructions:

  5010ec:       add x0, sp, #0x8

and

  5010ec:   lea    rdi,[rbp-0x20]