Repository navigation
fix(runtime): guard integer minimum during compiled division - #13
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The overflow guard preserves existing semantics and the regression test covers both operand positions, rounding, and signed zero.
0 open findings
What changed in this PR
Prevents Torch Inductor from miscompiling integer true division involving the signed 64-bit minimum.
Changes:
- Masks minimum values before negation.
- Adds deterministic scalar-Inductor regression coverage.
- Documents compiled-division semantics.
| File | Description |
|---|---|
src/array_vectorize/runtime/arith.py |
Safely preserves minimum magnitudes. |
tests/backends/test_jax_torch_compilation.py |
Tests scalar compiled division edge cases. |
docs/semantics.md |
Documents the JIT guarantee. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
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.
Problem and change
Torch Inductor's scalar C++ kernel can miscompile integer true division when a numerator or denominator is the signed 64-bit minimum. Negating that value overflows a signed C++ integer; optimizations then lose its magnitude bit. For example,
-(2**63) / -1could return0.0instead of9.223372036854776e18. This caused the compile job on #12 to fail depending on the runner's CPU path.Mask the minimum before eager negation and restore its magnitude bit pattern afterward. The helper remains backend neutral and generated function source is unchanged. Add a deterministic regression forcing scalar Inductor (
cpp.simdlen=1) and checking both operand positions, exact rounding, and signed zero. Retain the existing JAX/Torch regression and document the guarantee.Validation
CI=1 make check: passed, 960 tests, 97 skips, 96% coverage; lint and all four type checkers passed.make backends: passed, including the forced-scalar regression.make fuzz(five fixed seeds, 2,000 generated cases).make docs(strict build).