Skip to content

[Bugfix] Fix non-divisible nested modulo simplification - #3065

Merged
LeiWang1999 merged 2 commits into
tile-ai:mainfrom
haoyang9804:fix/2955
Aug 25, 2026
Merged

[Bugfix] Fix non-divisible nested modulo simplification#3065
LeiWang1999 merged 2 commits into
tile-ai:mainfrom
haoyang9804:fix/2955

Conversation

@haoyang9804

@haoyang9804 haoyang9804 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • update the bundled TVM iter-map simplifier to preserve a nested modulo when the inner split can wrap and its extent is not divisible by the outer modulus
  • retain the valid simplification for non-wrapping and divisible cases
  • add mirrored TileLang regression coverage

This prevents (x % 64) % 7 from being incorrectly rewritten as x % 7 during FlattenBuffer.

Depends on tile-ai/tvm#64.

Fixes #2955.

Testing

  • native build passed
  • TVM arithmetic suite: 39 passed
  • TileLang arithmetic suite: 39 passed
  • Metal codegen retains (threadIdx.x & 63) % 7

Summary

  • Updated the bundled TVM revision to preserve nested modulo expressions when divisibility is not proven.
  • Prevented (x % 64) % 7 from simplifying incorrectly to x % 7.
  • Added regression coverage for divisible and non-divisible extents.
  • Native build, TVM arithmetic, TileLang arithmetic, and Metal codegen tests pass.

C++ style / lint notes

  • The PR updates bundled TVM C++ code through a submodule revision.
  • It does not modify docs/developer_guide/cpp_style.md.
  • No new correctness or build issues are reported.
  • Any C++ API Style Audit findings are warning-only and do not block the change.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6cd86b84-e2bd-48e0-afd7-3b7153bc28fb

📥 Commits

Reviewing files that changed from the base of the PR and between f5c3614 and f8fd99e.

📒 Files selected for processing (1)
  • 3rdparty/tvm
🚧 Files skipped from review as they are similar to previous changes (1)
  • 3rdparty/tvm

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The vendored TVM revision was updated. Regression coverage was added for nested floormod simplification with divisible and non-divisible extents.

Changes

Nested floormod correctness

Layer / File(s) Summary
TVM revision and floormod regression coverage
3rdparty/tvm, testing/python/arith/test_arith_iter_affine_map.py
The TVM submodule reference now uses a newer revision. Tests verify that non-divisible nested modulo expressions remain unchanged and divisible expressions simplify to x % 8.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to f8fd9

This localized fix preserves nested modulo behavior for wrapping, non-divisible cases while retaining valid simplifications elsewhere, with regression coverage and passing test suites. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing incorrect simplification of non-divisible nested modulo expressions.
Linked Issues check ✅ Passed The submodule update brings the TVM simplifier fix, and the added regression test covers divisible and non-divisible nested modulo behavior. These changes address the requirements in [#2955].
Out of Scope Changes check ✅ Passed The changes are limited to the TVM submodule update and focused regression coverage. Both changes support the linked issue objectives.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@haoyang9804
haoyang9804 marked this pull request as ready for review August 22, 2026 12:54
@LeiWang1999

Copy link
Copy Markdown
Member

Thanks! The TVM-side fix has been merged via tile-ai/tvm#65.

This PR now updates 3rdparty/tvm from the previous PR head (1b372fa482cf) to the merged tilelang_main commit (121df796b1b3). The update is included in commit f8fd99ef.

@LeiWang1999
LeiWang1999 self-requested a review August 25, 2026 10:06
@LeiWang1999
LeiWang1999 merged commit fa9dfea into tile-ai:main Aug 25, 2026
6 of 7 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.

[BUG][Fuzzer][wrong-code] B[j % K] in a 2-D T.Parallel(M, N) loop silently reads the wrong element when K ∤ N instead of computing j % K

2 participants