fix(#776): aarch64 rotl clobbers a computed rotate operand (silent wrong result)#781
Merged
Conversation
…tch must not be dst i32.rotl/i64.rotl lower to `neg + rorv` (A64 has no native rotate-left). The pre-fix code reused `dst = alloc_temp()` as the neg scratch: `neg(dst,k); rorv(dst,n,dst)`. When the rotated operand `n` is a COMPUTED value, alloc_temp can hand back the register that held it (n,k are already popped), so `neg(dst,k)` destroys `n` before `rorv` reads it — a silent wrong result. Param-only rotates escaped it because `n` sits in a distinct argument register. Introduced by #769 (aarch64 m2). Fix: compute `-k` in `k`'s own now-dead register (`neg(k,k); rorv(dst,n,k)`). rorv reads `n` (intact) + `-k` and writes `dst` — reads-before-write holds even if `dst` aliases an input, and n/k are distinct stack slots so `neg(k,k)` never touches `n`. Red-first gate: i32_rotl_computed / i64_rotl_computed added to the m2 differential (n = an add temp). RED on the pre-fix binary (A64=-49 vs wasmtime=1183502082 etc., 7 cases), GREEN after (182/182 vs wasmtime). Rides the already-CI-wired aarch64-oracle job. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJK5LZZEkV5smCY1jKn18L
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Silent miscompile in
i32.rotl/i64.rotlon the aarch64 backend when the rotated operand is computed — introduced by #769 (m2). Fix-first patch → v0.45.2.Root cause
rotl=neg + rorv(no native A64 rotate-left). The neg scratch reuseddst = alloc_temp():neg(dst,k); rorv(dst,n,dst). For a computedn, alloc_temp can return n's freed register, soneg(dst,k)destroysnbeforerorvreads it. Param-only rotates escaped (n in a distinct arg reg).Fix
neg(k,k); rorv(dst,n,k)— compute-kin k's own dead register;rorvreadsnintact +-k. One-line-equivalent, reads-before-write safe for any dst aliasing.Verification (red→green)
i32_rotl_computed/i64_rotl_computedcases (n = add temp) in the m2 differential.i32_rotl_computed(0x12345678,4) A64=-49 vs wasmtime=1183502082, 7 fails).aarch64-oraclejob.Closes #776.
🤖 Generated with Claude Code