Skip to content

t27b: SSA INC-IF fold — hot loop 9→8 instructions, beats GCC -O2's 10 (see #14012) - #14027

Merged
gHashTag merged 1 commit into
masterfrom
claude/ssa-inc-14012-v2
Nov 17, 2026
Merged

gHashTag merged 1 commit into
masterfrom
claude/ssa-inc-14012-v2

Conversation

@gHashTag

Copy link
Copy Markdown
Collaborator

see #14012 #12871 #13453
(the LICM half of #14012 already landed on master inside the t27b release squash; this lands the SSA half)

Boundary

bench_audit hot loop was 9 instructions after the LICM half; clang -O2's shape
is 7. The gap is the increment-in-place: w = w + c destroys the old value that
an arm w - c needs, so t27b emitted a separate sub. This PR removes it.

What landed

  • Spec middle_end.t27: ssa_inc_facts — the four gates of the INC-IF fold
    (step adjacent, arms assign-only, exactly one branch defines w, every w-read is
    the fold w - c or a plain new-value read). 5 tests.
  • Spec ifconv_plan.t27: arm_reads_ok_ordered + select_may_emit — with
    ordered emission a plain-local arm may read a selected local when the read's
    select emits BEFORE that local's select (the read lands on the pre-select home).
    The old law stays for un-ordered callers. 6 tests.
  • gen twins for both.
  • Impl codegen.rs:
    • ssa_local_inc (runs before homes are planned): rewrites
      w = w + c; if (w cmp k) ... else ... to vt = w + c; if (vt cmp k) ... else ...; w = vt — same op (a checked add keeps its trap site), fresh __t27b_ssaN
      temp, the fold arm reads w's home (old value).
    • ifconv: ordered select emission (reader first, read local last), gated by the
      new law; mutual-read pairs bail.

Evidence

  • bench_audit hot loop: 9 -> 8 instructions (cmp, csinc acc, add vt, cmp vt,
    csel prev [reads OLD w], csinc w, sub count, cbnz) — now 2 fewer than GCC -O2's
    10 for the same source.
  • A/A: 186 conformance (1635 tests) + 17 shootout + 65 queen files — 0
    regressions
    ; the 2 queen fails are pre-existing (same in runs/ref_complete.txt).
  • Tests: middle_end 15/15, ifconv_plan 22/22; bench_audit --check 0 mismatches.
  • Wall clock on a quiet host: OLD 1.32 / NEW ~1.36 / clang 1.17-1.22 ns per call
    — the loop is dependency-chain bound; the removed instructions were off the
    critical path, so the win shows in code size, not yet in wall clock.

Constraints

  • No hand-written layout, no semantics change, no paid tokens; all work on free/local capacity.

… reads the old w via ordered selects; bench_audit hot loop 9 -> 8 insns, beats GCC -O2's 10 (see #14012)
@github-actions

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-11-15 20:52:38 UTC

Summary

Status Count
Total Open PRs 47
PRs with Failing Checks 44
PRs with All Checks Green 3
READY 0
FAILING 44
PENDING 0
NO CHECKS YET 0

These columns do not partition: 0 + 44 + 0 + 0 = 44, and there are 47 open PRs. A PR is being counted twice or not at all.

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=29c50ada25c9 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@gHashTag

Copy link
Copy Markdown
Collaborator Author

Decision summary for the merge review (owner request, 2026-11-16):

  1. Instruction-count win — measured and reproduced: bench_audit hot loop 9 -> 8 instructions (asm in the PR body); t27b now 2 fewer than GCC -O2's 10 for the same source.
  2. Wall-clock win — NOT established: quiet-host interleaved runs give OLD 1.32 / NEW ~1.36 / clang 1.17-1.22 ns per call. NEW was slightly SLOWER than OLD in that sample; no spread/repeatability data yet, so this is neither a proven win nor a proven regression. The loop is dependency-chain bound; the removed instructions were off the critical path.
  3. The <= clang criterion — NOT met on wall clock (NEW > clang in the one quiet sample). It was met on instruction count only (8 vs clang 7 is still not <=; the criterion as written in t27b: SSA value-tracking + LICM imm12 hoist -- 10 -> 7 hot-loop instructions on bench_audit #14012 was "at most 8 instructions, <= clang ns on the same host" — half of it).

Treat this PR as a code-size improvement pending a repeatable wall-clock protocol (fixed host, N>=10 interleaved runs, min and median reported) before any performance claim. Merge decision is the owner's.

@gHashTag

Copy link
Copy Markdown
Collaborator Author

Wording correction to the decision summary above (owner, 2026-11-16):

The <= clang criterion is not met on EITHER axis:

  • instructions: 8 > 7 (clang) — t27b beats GCC -O2 (10 -> 8) and improves on its own OLD (9 -> 8), but does not reach clang;
  • wall clock: NEW ~1.36 vs clang ~1.17-1.22 ns in the single quiet sample, no spread data.

What IS established: the instruction-count improvement over OLD (9 -> 8) and over GCC -O2 (10 -> 8), and 0 A/A regressions (268 files). Nothing else is claimed.

@gHashTag
gHashTag merged commit bf1598f into master Nov 17, 2026
41 of 49 checks passed
@gHashTag
gHashTag deleted the claude/ssa-inc-14012-v2 branch November 17, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant