Skip to Content
marmot

Problem

MIR's linear scan gives an interval one location for its whole length. An interval with a call inside needs a callee saved register (x86-64: rbx, r12 to r15, no XMM register is callee saved, arm64: x19 to x28, d8 to d15). When none is free, the whole interval goes to a stack slot. So every use is a load and every definition a store, also in a loop far from the call. Float values on x86-64 always take that path. Examples: spectralnorm's accumulator across the a(i, j) call, which inlining fixes when the callee is a leaf. Also loops that call a runtime helper once per iteration.

Change

When a crossing interval finds no callee saved register, it can take a caller saved register instead. The emitter stores it to its spill slot before each call inside the interval. It loads it back after the call. The slot is the one the interval would have had.

  • Choice: take this path when the interval's uses outside calls outnumber twice the calls inside it. A use costs a load in the slot form. A call costs a store and a load in this form. Else the slot as today. Uses and calls are counted per interval when positions are numbered.
  • Emission: each call in the interval saves the register before its argument moves and restores it after the result moves. The set to save at a call is the intervals with this kind whose range holds the call position. A call that returns into a register held by such an interval cannot happen. The result's interval starts at the call, and the saved interval keeps its register.
  • Interaction: the panic call (followed by unreachable) saves nothing. rt_setjmp functions keep memory only, as today.

Properties

  • Semantics: the value is in its slot during the call and in its register outside. The conservative stack scan sees the slot during the call, so a pointer stays visible to the collector exactly as in the slot form.
  • Code size: two instructions per saved value per call, against one per use in the slot form.

Measurement plan

Static: spill loads and stores per function on the tuios corpus and goldmark. perfcmp dev with and without the switch. Conform dev and gcstress. fuzz.

On this page

Was this page helpful?

Report an issueOpen issues