Repository navigation
HighByteZero trusts only the bytes the selection keeps clean - #98
Merged
Merged
Conversation
HighByteZero (#90) took every byte's place as zero-extended to 16 bits. The selection masks a byte only where a reader needs it clean (Selection.maskResult): one that only byte-wise code reads keeps whatever high byte its code left, such as a 16-bit shift's truncation ($FFFF for a >> 15 of a negative a). A 16-bit EOR with such a place was then believed to leave B at 0, and a byte counter's increment after it went to 8 bits and was stored with that high byte. The predicate is now per function: truth values, byte parameters, and the bytes in Selection.clean (masked, or clean by themselves where a reader needs it), kept per function since the LIR passes run after the selection of all of them. Found by the random loop programs, seeds 20787012 and 20787028; exec/regress_byte_high_byte.c is the program cut down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
skerkewitz
approved these changes
Nov 30, 2026
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.
What
Fixes the miscompile behind today's two failing random loop programs (seeds 20787012 and 20787028). They block CI for every pull request today, #97 included.
HighByteZero(from #90, eight-bit stretches) takes 16-bit code to 8 bits where the high byte of A (B) is known to be 0. To know that, it assumed every byte's place in memory holds a high byte of 0. But the selection masks a byte only where one of its readers needs a clean high byte (Selection.maskResult). A byte that only byte-wise code reads keeps whatever high byte its code left.In the failing programs that byte was
a[c] >> 15, truncated to a byte:$FFFFin its place for a negativea[c]. A 16-bitEORwith it was taken to leave B at 0. The loop counter'sc += 2right after went to 8 bits, was stored in 16 bits with that high byte, and the loop then indexed and ended wrong.How
MirCodeGen.zeroExtendedbecomes per function. It now takes a byte's place as clean only for:Selection.clean: masked, or clean by themselves where a reader needs them clean.The selection already relies on that set being right. It is rebuilt for each function during selection, while the LIR passes run after all functions are selected, so a copy is kept per function (
cleanBytes).Seed 20787012 is the same bug, although the pass bisect named
Widths. WhenWidthschanges a function,MirCodeGenalso finishes the version without it, to compare worst cases, and thatfinishruns with no pass limit (PassLimit.none()).HighByteZerotherefore ran unlimited there, anddev/bisect_passes.shcan't see it. I confirmed it by switchingHighByteZerooff ondevelop: seed 20787012 then passes.Verified
./gradlew build: 1,275 tests, 0 failed, 13 skipped, today's random programs included.exec/regress_byte_high_byte.cis seed 20787028 cut down to 20 lines. It fails ondevelopand passes with the fix.dev/bench_examples.sh,developagainst this branch: geometric mean 1.000. Mode 7: 10,401 to 10,418 master cycles of work per tick (+0.2 %). Schach: 359,956 to 360,013 (+0.02 %). The others are unchanged within a few cycles.What follows
backend-output.txtchanges for every example. Incost-baseline.txtone static worst case moves: Schach's_unmake_move, 3,114 to 3,140 master cycles.docs/game-findings.md.StyleGuideTest, documents, the book: unchanged.Open
PassLimit.none(). That's worth a look on its own.🤖 Generated with Claude Code