Skip to content

[FIX][S-TIR] Preserve loop variable types when eliminating unit-extent loops - #20999

Merged
mshr-h merged 1 commit into
apache:mainfrom
milkHongYe:loop-partition-int64
Nov 19, 2026
Merged

mshr-h merged 1 commit into
apache:mainfrom
milkHongYe:loop-partition-int64

Conversation

@milkHongYe

Copy link
Copy Markdown
Contributor

LoopPartition replaces unit-extent loop variables with an int32 zero, regardless of the original variable type. For int64 loops, this can produce addition expressions with mismatched int32/int64 operands.

Construct the replacement zero using the loop variable's type.

Add int32/int64 regression tests that check unit loops are eliminated without introducing mismatched addition operands. The int64 case fails before the fix and passes afterward.

The immediate substitution error reported in #20879 was not reproduced on this checkout; instead, the pass produced expressions with mismatched operand types. The regression test checks this type inconsistency.

Fixes #20879.

@milkHongYe

Copy link
Copy Markdown
Contributor Author

Hi @akaashrp, @mshr-h, @yzhliu,
Could you please take a look at this PR when you get a chance? Thank you!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change preserving integer types during unit-extent loop elimination.

No open issues 🎉

What changed in this PR

Updates S-TIR’s LoopPartition pass to preserve integer types when eliminating unit-extent loops, addressing the type mismatch reported in #20879.

Changes:

  • Constructs replacement zeros using the original loop variable’s type.
  • Adds int32/int64 regression tests checking loop elimination and matching addition operand types.
File Description
tests/​python/​s_tir/​transform/​test_s_tir_transform_loop_partition.py Adds parameterized regression coverage for type-safe loop elimination.
src/​s_tir/​transform/​loop_partition.cc Preserves the loop variable’s type in the replacement zero.

Review effort: Max

@milkHongYe

Copy link
Copy Markdown
Contributor Author

Hi @mshr-h, thanks for arranging the Copilot review. It reported no issues, and this PR is still awaiting a maintainer review. Could you please take a look when you have a chance, or suggest an appropriate reviewer? Thank you!

@mshr-h
mshr-h merged commit bfebeee into apache:main Nov 19, 2026
8 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][TIRx][S-TIR] LoopPartition fails when unrolling an int64 loop with extent one`

3 participants