Skip to content

Conversation

@weinbe58
Copy link
Member

@weinbe58 weinbe58 commented Jan 8, 2026

In this PR I implement a rewrite that effectively rewrites:

for ele in ilist_value:
    ...

to

for i in range(len(ilist_value)):
    ele = ilist_value[i]
    ...

which is equivalent in terms of execution but is easier to massage into a state that can be unrolled by combining this rewrite with HintLen rewrite rule effectively allowing the iterable argument of the new scf.For statement to be known at compile time even if ilist_value is not a constant.

The reason I think we should have this rule instead of implementing a specialization in the unroll of the for loop is that this rewrite is independent of the unroll rewrite and so you do not need to worry about a dependency between the unroll rule and the ilist dialect.

@weinbe58 weinbe58 changed the title Rewrite For loop over Ilist to a ranged For loop for better folding. Rewrite For loop over IList to a ranged For loop for better folding. Jan 8, 2026
@weinbe58 weinbe58 changed the title Rewrite For loop over IList to a ranged For loop for better folding. Rewrite For loop over IList to a ranged For loop for better unrolling. Jan 8, 2026
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11768 10504 89% 0% 🟢

New Files

File Coverage Status
src/kirin/dialects/ilist/rewrite/to_range_loop.py 100% 🟢
TOTAL 100% 🟢

Modified Files

File Coverage Status
src/kirin/dialects/ilist/rewrite/_init_.py 100% 🟢
TOTAL 100% 🟢

updated for commit: 459191a by action🐍

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

PR Preview Action v1.8.0

🚀 View preview at
https://QuEraComputing.github.io/kirin/pr-preview/pr-597/

Built to branch gh-pages at 2026-01-08 15:19 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@weinbe58 weinbe58 requested a review from Roger-luo January 8, 2026 15:20
@weinbe58 weinbe58 added P-Low Priority: low priority issues and tasks. C-enhancement Category: This is an enhancement of an existing feature labels Jan 8, 2026
@weinbe58 weinbe58 mentioned this pull request Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category: This is an enhancement of an existing feature P-Low Priority: low priority issues and tasks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants