Skip to content

fix(runtime): guard integer minimum during compiled division - #13

Merged
egparedes merged 1 commit into
mainfrom
fix-scalar-inductor-int64-min
Oct 7, 2026
Merged

egparedes merged 1 commit into
mainfrom
fix-scalar-inductor-int64-min

Conversation

@egparedes

@egparedes egparedes commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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) / -1 could return 0.0 instead of 9.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.
  • Hosted make backends: passed, including the forced-scalar regression.
  • make fuzz (five fixed seeds, 2,000 generated cases).
  • make docs (strict build).
  • Independent semantics review: APPROVED, 243,504 comparisons across NumPy and array-api-strict, including signed/unsigned boundaries, boolean inputs, scalar operands, broadcasting, and floating edge values.
  • All nine GitHub CI checks passed, including Python 3.12/3.13/3.14, dependency floors, and compilation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@egparedes
egparedes merged commit 2e4188d into main Oct 7, 2026
10 checks passed
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.

2 participants