Repository navigation
Make LowIR one language and compile each object identically from its text - #174
Merged
vishvananda merged 8 commits intoNov 16, 2026
Merged
Conversation
vishvananda
force-pushed
the
fix/lowir-one-language
branch
from
November 16, 2026 21:38
8b23bdb to
476eb53
Compare
vishvananda
merged commit Nov 16, 2026
476eb53
into
perf/reuse-release-library-objects
53 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This branch is on top of #173 and ends with the two commits of #175, so the
three can be fast-forwarded together.
One LowIR language
There were two LowIR dialects. The host-object classes (x87, complex_x87,
sseup, memory results,
classes=on variadic call arguments and on va_arg)were read only when a program came from the object compile, and lowiropt
rejected them. A program that lowiropt read and wrote could then not be
compiled to the same object.
These facts are necessary: the native objects need them for long double,
__int128, vector and large object boundaries, and the Wasm objects use thesame fields. They are now part of the contract (pa8/lowir.md "Object ABI
Conventions" and "Variadic Argument Access"):
Program::object_factsand the numeric classspelling are removed.
valid_object_classes, says which classes a type can have. Thevalidator checks argument and va_arg classes against the real operand.
a behavior fixture: 12 checks through pointer calls and variadic boundaries.
lowiropt -O0hasread and written it, so lowiropt must keep every fact.
Two PA8 fixtures change:
300-bad-classes-unknownnow uses an unknown word,and
300-bad-result-classes-memoryis removed because a memory result is nowvalid. No other references change in that commit; commit 6 changes one
(below).
Commits
Choose block lane runs independently of how the host sorts repeated
addresses. The SIMD difference between the GCC-made and the Clang-made
lowiropt came from
std::sort, which is not stable: the two standardlibraries put stores to one address in different orders. New PA33 fixture:
o3/500-lanes-of-a-copy-written-again.t.Make host object classes part of the LowIR contract (above).
Leave x86-64 classes off soft-float helpers on Wasm targets. Wasm objects
do not change.
Give the runtime unroller's group loops a block kind of their own. A full
unroll gave its copy of a plain block the kind
Unrolled, and the runtimeunroller reads
Unrolledas its own group loop. A block read from text isalways plain, so at O3 the same source unrolled differently from text and
from memory (x86 and Wasm). The group header now has the kind
UnrolledGroup, which prints asunrolled_Nas before. The kind is addedat the end of the shipped
lowir_local_model.henum. New PA33 fixture:500-o3-unrolled-copy-as-loop-header.cpp.Compile Wasm objects identically from their LowIR text. The Wasm back end
depended on in-memory ids and order. Now:
instruction defines gets no local;
-cand the--emit-lowir -g0object half use the same lowering mode.check_wasm.plnow compares, at each level, the object compiled from theobject LowIR (after
lowiropt -O0) with the direct object byte for byte.The PA37 README states this. The PA33 round-trip script takes
--target.PA37 and PA38 (whose
test-wasmruns the same checker) now buildlowiropt, as does the WASI reference export job.Export the optimized LowIR of an object compile with
-S -emit-lowir(below).
and 8. The two commits of Run and publish the complete WASI self-build on dedicated Intel #175, unchanged: find Intel dispatches by unique
runner identity, and run and publish the full WASI self-build on dedicated
Intel.
Optimized LowIR from the driver
cppgm -S -emit-lowirwrites the LowIR that-ccompiles, after the LowIRoptimizer, as clang's
-S -emit-llvmdoes.-fno-lowir-passescompileswithout the LowIR optimizer; the back end still runs at the -O level:
--emit-lowirwith a debug level and a.lowiroutput) now runs this driver path, so there is one producer. ThePA33 driver lane references do not change. For a Wasm target with
-gline-tables-only, that text now has no debug locations, as-clowersnone for Wasm.
--helplists them after the course flags; the shipped help text does not change.
To give the same object from the text, three things changed:
optimizer's compaction leaves them. Before, it numbered a temporary where
the text first names it, which for a phi operand on a back edge is before
its definition, and the native register allocator then broke ties
differently. Every reader of LowIR text (
-c x.lowir, lowiropt, lowir)takes this one route.
remove the last call of a signature, and the text does not write it.
symbols such as switch tables.
Direct Wasm objects can change in the last two cases. Native objects do not
change.
lowiropt orders commutative operands by temporary number, so its output
changes where the numbering moved. One reference changes, regenerated with
make ref-test:pa33/tests/o1/200-separate-latch-counter.refnow writesbinary add i64 %sum, %nextfor%next, %sum. This is presentation, whichthe course comparison absorbs, and the fixture's property (where the step
may move) is unchanged. The renumbering stays in the reader rather than in
the object path alone, so that all readers take one route. Its cost on a
5.4 MB optimized text from an LLVM unit, in instructions: lowiropt -O0 +0.8%
(read and write only), lowiropt -O2 +0.15%,
cppgm -O2 -c x.lowir+0.1%.Source compiles do not read text.
The tests are solution lanes, and the export prunes them:
maintainer/Makefileturns on an optimized-text check in the objectround trip: native, with and without debug information, O0 to O3: 52/52.
maintainer/Makefileturns on the same check incheck_wasm.plforeach fixture and level. A harness test covers the check.
Checks
CPPGM_LOWIR_DIRECT_TEXT_COMPARE=1 make test-report: 11320/11320make test-debuginfo,make -C pa35 test-through-pa5,make -C pa36 test-smoke,make test-harness: passboth Wasm targets at O0 to O3: 0 differences. PA38
test-wasm(Cfixtures): 105/105.
instructions identical at O0, O2 and O3 (ratio 1.0000). Cycles are within
noise (least-of ratios 1.004, 0.998 and 1.004 for commits 1–5, and 1.003,
1.003 and 1.005 for commit 6; an O3 A/A run gives 1.001). The native objects
of those units are identical (O2 and O3 for commits 1–5; O0, O2 and O3 for
commit 6).
for commit 6 add more time in this repository only.
🤖 Generated with Claude Code