Skip to Content
marmot

tier0 is the direct code generator of dev builds (arm64 Mach-O and x86-64 ELF). This page records every tier0 experiment of the last days: what, why, the measurement, the verdict and the next step. perfcmp compares two builds on wall time, CPU time, peak RSS and size, 7 runs per side. A line is worse past 2% (time) or 3% (memory), and only exit 0 counts as a pass. "noise" is each side against itself.

Target independent middle and per target emitters

  • What: the arm64 and x86-64 code generators became one shared middle and two thin emitters. The middle holds type layout, ABI, fused compares, folded address arithmetic, nil check decisions, linear scan, frame layout with shared slots and stack maps.
  • Why: the arm64 improvements of the week before (code 40% and then 24% smaller, shared slots) never reached x86-64. So Linux dev code was several times larger and slower.
  • Measurement: arm64 and x86-64 objects byte identical on 449 lowered modules (fmt hello, the goldmark world test, the compiler itself). tier0 time 2178 ms before, 2183 ms after on the six largest modules of the compiler.
  • Verdict: landed (8c612468).

x86-64 on the middle

  • What: the x86-64 emitter takes its decisions from the middle: register allocation, shared stack slots, fused compares, decided nil checks, shared epilogues.
  • Why: the brief's root cause, Linux users had the old tier0.
  • Measurement: goldmark x86-64 text 9,975,615 to 4,518,462 bytes. perfcmp linux/amd64 dev, main a1d8324d against the change: geomean wall 0.811, CPU 0.812, RSS 0.983. Size about 0.68 (tuios 0.593). iface 0.556, matmul 0.723, strconcat 0.693. Exit 0. arm64 objects byte identical.
  • Verdict: landed (87e58407), on by default.

Pointer-free data sections

  • What: globals that hold no pointers, weak zero values included, go to their own data and zero fill sections. The collector can then skip them. The sections are Mach-O __noptrdata and __noptrbss, and ELF .data.marmot.noptr.SYM and .bss.marmot.noptr.SYM. Used by the front end's opt-in pointer-free layout.
  • Measurement: objects without such globals are byte identical (goldmark, 70 modules, both targets). The ELF names had to carry the symbol suffix before the linker script gathered them. The unit test then looked for the Mach-O name on Linux and failed. fixed.
  • Verdict: landed (41bd1170, a4091518, 575eba2e, test fix d2659c5f). The switch that uses it belongs to the front end.

Package init code in its own text section

  • What: functions marked as package init go to __TEXT,__StaticInit or .text.startup, so the linker packs them together.
  • Why: 306 of 550 text page faults of the tuios dev startup on Linux were in init functions.
  • Measurement: objects without such functions byte identical (goldmark, both targets).
  • Verdict: landed (dae2f264). The front end decides when to mark functions.

Card barrier lowering

  • What: the card mark of the card stub write barrier becomes a conditional call to a register specific stub.
  • Why: dev builds with the card stub barrier did not link.
  • Verdict: landed (b9e5d804). Modules without the barrier unchanged.

MIR, tier0's own function IR

  • What: a second code generator on a scalar SSA form. It splits aggregates into pieces, forwards copies and folds constants. It shares pure operations within a block (CSE) and folds constant offsets into memory operations. Liveness and linear scan with caller and callee saved registers. Shared spill slots. Emitters for both targets. Functions it does not cover take the older emitters.
  • Measurement, macOS (arm64), dev, old emitters against MIR: geomean wall 0.645, CPU 0.641, RSS 0.986. The machine load was above half the CPUs at the end, so the result is noisy. Linux, at 575eba2e, default against MARMOT_TIER0_MIR=1: dev wall 0.863, CPU 0.863, RSS 0.979. tuios wall 0.892, size 0.822. sketch wall 0.902, size 0.820. nbody 0.619, matmul 0.733. strconcat 1.099 (worse). O2 0.994, release 0.998 (same code in those modes). Noise 1.011 to 1.012. Exit 0.
  • Gates: Linux conform dev and gcstress, fuzz 200 programs with 0 differences. macOS conform and fuzz.
  • Verdict: landed opt-in (18455acd). Made the default (14d3417b), then reverted (77acef69) when a CSE bug showed (next section). Made the default again (9660f5c9) after the fix. Reverted again (b8e0a99c) when the tuios -release binary differed with and without the switch. A control (two release builds with the same setting) decides whether that build is simply not deterministic.
  • Reflip measurement at f0220956, default against MIR on, MARMOT_TIER1=0: dev geomean wall 0.866, CPU 0.866, RSS 0.978 (noise 1.008). tuios wall 0.912, size 0.822. strconcat 1.098. O2 geomean 1.003 (noise 1.016). Release was INCONCLUSIVE on noise 1.033, and release builds never run tier0 (the driver passes -tier0 only to dev builds). 12 of 13 perfcmp programs are byte-identical with -release with and without the switch, the tuios -release comparison is queued.
  • Next: the allocation change (below) for strconcat.

MIR CSE bug: float32(x) and float64(x) shared one result

  • What: the CSE key held the operation, operand width and operands, not the result's class and width. A conversion of one value to f32 and to f64 in one block became one value, so one of the two printed garbage.
  • How it was found: conform on a build with the narrow saturating conversions (below) failed run/core/float_conv and hard_int_conv_edges. Their main functions also convert floats to small integers, which MIR did not cover. Before that change, those functions went to LLVM. So the gate for the default flip could not see the bug.
  • Fix: the key includes the result class and width (fa9d34de). New conform test run/core/conv_cse and a fuzzer pattern that converts one value to two types in one statement (cfc9a774). Before the fix: conv_cse fails, fuzz has 17 differences in 40 programs. After: both pass.
  • Gates on the fix with MIR on: conform dev and gcstress 1545 of 1554. 8 failures are known. card_fresh_move timed out under gcstress, because the test tree is older than that test's gcstress interval. Fuzz 200 programs, 0 differences. perfcmp against the build without the fix: INCONCLUSIVE (noise 1.020), geomean 0.999.
  • With MIR off (the landed default), hello and the 45 bench programs have identical loaded sections with and without the fix.
  • Verdict: landed. Lesson: the gate needs a test for each MIR pattern on its own. A pattern inside a function that MIR does not cover for another reason is not tested.

Checks decided by dominating compares (DOMCHECKS)

  • What: a branch on a compare that a dominating branch already decided goes one way. A signed loop test with a nonnegative start also decides the unsigned bounds check. Nil and bounds checks in loop bodies and their panic blocks go away.
  • Measurement: goldmark MIR text arm64 -2.6%, x86-64 -2.8%. perfcmp at 575eba2e, MIR against MIR plus DOMCHECKS: dev geomean wall 0.913, CPU 0.914, RSS 0.998. strconcat 0.486, tuios 0.962. O2 0.994, release 0.996 (same code). Noise 1.005 to 1.013. Exit 0.
  • Gates: Linux fuzz 200 programs, 0 differences. Linux conform dev and gcstress: 1540 of 1550, with two gcstress timeouts that DOMCHECKS does not cause. peano takes 65 to 71 seconds under gcstress with every setting (MIR off, MIR, MIR plus DOMCHECKS, an older build). card_fresh_move times out without MIR too.
  • Verdict: opt-in (MARMOT_TIER0_DOMCHECKS=1). Next: flip after the MIR reflip.

Saturating conversions to narrow integers in MIR

  • What: llvm.fptosi.sat and llvm.fptoui.sat to i8, i16 and i32: the 64-bit saturating conversion, clamped to the result's range.
  • Why: 9 of the 38 tuios functions MIR did not cover. With the older emitters they went to LLVM (for example 1, 2 and 3 LLVM fallbacks in three tuios modules, 0 with the change).
  • Measurement: new unit test with NaN, infinities and range edges on x86-64. perfcmp dev against main: INCONCLUSIVE (noise 1.029), geomean 0.995.
  • Verdict: pending, needs an exit 0 perfcmp.

MIR register allocation around panic blocks

  • What: for register allocation, a block that only panics gets the number right after its one predecessor. The block stays at the end of the code. A call followed by unreachable clobbers nothing.
  • Why: strconcat was 10% slower with MIR. Its inner loop kept the index and the length on the stack. The panic block at the end of the function used both, so their intervals reached over the later print calls. They needed callee saved registers and were spilled when those ran out. The old emitters had the same spills with a longer loop.
  • Measurement: strconcat inner loop 19 instructions with 5 loads and 1 store, now 15 with the byte load only. main 176 to 161 instructions. perfcmp dev, with and without the change (both with the narrow conversions): INCONCLUSIVE (noise 1.027), geomean 0.871, strconcat 0.522.
  • Verdict: pending. Its own gate (a root with main plus only this change) is being built.

Aggregates of up to 64 pieces in MIR

  • What: MIR takes functions with aggregates of up to 64 scalar pieces (was 32).
  • Measurement on tuios (507 lowered modules, x86-64), functions left to the older emitters for their aggregates and total code bytes: 32 pieces 295 and 40,074,250. 64 pieces 87 and 39,957,799 (-0.3%). 128 pieces 67 and 40,003,357. 256 pieces 31 and 40,183,275. perfcmp dev with and without 64: exit 0, geomean wall 0.989, CPU 0.994 (noise 1.017).
  • Verdict: 64 pending its gate after the reflip (it was measured on top of the allocation change). 128 and 256 dropped: more coverage, larger code.
  • Next: aggregates over 64 pieces held in memory instead of pieces.

Inlining small leaf callees in MIR (MARMOT_TIER0_INLINE=1)

  • What: a direct call to a one-block leaf of the same module is replaced by the callee's operations at the call's location. The leaf has at most 24 operations, no calls and no memory access. Its body is final at link, and it has no no_inline. After the design review in the backend, linkage is limited to external, linkonce_odr and weak_odr. Loads left out so no fault can fall inside an inlined body.
  • Why: spectralnorm dev runs 8.8x -O 2. a(i, j) stays a call in the inner loop, and across it the accumulator and two integers lose their registers.
  • Measurement: tuios corpus, x86-64, MIR on: code 39,957,799 to 39,960,228 bytes, fallbacks unchanged (MIR 87, LLVM 0). Unit test: 5 calls to 1, same results. Fuzz with both switches: 200 programs, 0 differences. Conform dev and gcstress: 1544 of 1556 with four gcstress timeouts (peano, json_parser, card_fresh_move, goroutine_sum). goroutine_sum takes 171 to 269 seconds under gcstress with and without the change, against a 200 second limit. perfcmp dev queued last.
  • Verdict: opt-in, pending its gates.
  • Next: multi-block callees with their panic paths and inline records in the pc table, then loads.

Values over calls in caller saved registers (MARMOT_TIER0_CALLSAVE=1, x86-64)

  • What: take an interval with calls inside and no free callee saved register. It takes a caller saved register, in place of a stack slot for its whole length. All calls inside must be plain calls, and its uses must outnumber twice the calls. The emitter stores it before each call and reloads it after.
  • Why: x86-64 has no callee saved XMM register and five callee saved general registers. So float values over a call, and integers when those five are taken, became loads at every use. Second pick of the research file. Reviewed in the backend, with one clobber list. The only calls that the emitter adds itself (memmove, memset and fma) keep the slot form. Loop weights and merged saves for consecutive calls are the next steps.
  • Measurement: unit test with a float accumulator over a call in a loop: 51 to 49 instructions, same result as C. tuios corpus: code 39,957,799 to 39,967,241 bytes (+0.02%), fallbacks unchanged. perfcmp, conform and fuzz: not run yet.
  • Verdict: opt-in, pending its gates.

Reviews of other designs

  • Bounds check rule B4 (verify): found two soundness holes. A loop bound guard was taken from any compare predicate, so a guard i >= n let a wrapping index pass as non-negative. And an unsigned guard against y with y + K equal to the length did not prove i >= 0 when y is negative. Both confirmed with programs and fixed. The fuzzer got these shapes.
  • Build schedule (backend): the review asked for CPU throttling data beside the timeline, and CPU time beside wall time. It also asked for admission by measured peak, a fixed link order, and a private cold cache per run.

Cache keys of the tier0 switches

  • Question: could a perfcmp with -b-env on one root have compared cached objects of side A?
  • Finding: the dev object key is built from the driver's module key. That key hashes every MARMOT_* variable except a short denylist, so every keyed module carries the switches. Modules without a driver key use their text plus the backend fingerprint, which did not list the tier0 switches. Examples are the home instances module and a part whose save failed. A backend change adds them.
  • Proof: spectralnorm, one fresh cache, build A then B: the .text of B differs from A for MIR, DOMCHECKS, INLINE and CALLSAVE. The gates stand.

Measurement notes

  • For most of a day, the shared Linux machine had too much load for a 2% verdict. Several perfcmp runs came back INCONCLUSIVE, with noise 1.020 to 1.029 and load 4 to 16 at the start.
  • tests/conform takes its tests from the tree it runs in, not from the root it tests. So a gate from an older tree misses newer tests and their settings.
  • Dev builds of the same program from two roots differ in non-loaded sections. Compare the loaded sections (or .text) to show that code is unchanged.

On this page

Was this page helpful?

Report an issueOpen issues