what does Spill mean in ARM ISA

Viewed 666

I have write some test code, just for testing the stack overflow.

int MyFunc(long c)
{
    char buffer[12];
    return sprintf(buffer, "xxxxxxxxxxx%ld", c);
}

when I compile it to ARM64 assembly, I got the result

MyFunc(long): // @MyFunc(long)
  sub sp, sp, #32 // =32
  stp x29, x30, [sp, #16] // 16-byte Folded Spill
  add x29, sp, #16 // =16
  adrp x1, .L.str
  mov x2, x0
  add x1, x1, :lo12:.L.str
  add x0, sp, #4 // =4
  bl sprintf
  ldp x29, x30, [sp, #16] // 16-byte Folded Reload
  add sp, sp, #32 // =32
  ret

so, what does 16-byte Folded Spill mean? and why?

1 Answers

Stackoverflow.com is the perfect place for stack spill questions. =)

16-byte is because we are saving two 8-byte registers to the stack.

Folded for this one I am going to have to guess. Folding is when math operations are simplified combined. I going to go out on a whim and say it does not apply here and that it’s just a generic compiler message that only sometimes applies. If we had several of these in a row to save many registers to the stack and incremented the stack pointer(sp) just once then it would be combined because we would be using -32+16=-16 and this does not cause any extra math.

sub sp, sp, #32 
stp x27, x28, [sp] 
stp x29, x30, [sp, #16] <--- folded because we decrement sp once on 1st row

Spill is the process of saving registers to memory because we need the extra registers. This is often referred to as spilling the registers to memory.

Related