Skip to content

ConstProp early termination optimization#632

Open
johnzl-777 wants to merge 7 commits intomainfrom
constprop-early-termination
Open

ConstProp early termination optimization#632
johnzl-777 wants to merge 7 commits intomainfrom
constprop-early-termination

Conversation

@johnzl-777
Copy link
Copy Markdown
Contributor

A (looser) form of this optimization exists in QuEraComputing/bloqade-circuit#736. The idea is to stop constprop from iterating through a loop if loop_vars has converged, preventing a bunch of unnecessary future iterations.

Claude pointed out to me that if there's some dependency on the iteration variable triggering an impure operation in the loop body, the original fix without the guard you currently see would improperly denote the loop as entirely pure.

I already check for no iteration variable dependency in the bloqade-circuit stuff I'm working on but I don't see the harm in having it duplicated here.

@Roger-luo agreed this optimization is worth including in Kirin, with kudos to @weinbe58 and @jasonhan3 for pointing this optimization out to me.

Some benchmarks can be seen here, running against a trivial:

@structural_no_opt
def loop_test(x: int) -> int:
	for _i in range(...):
		x = x + 1
	return x

From range(10) to range(30_000):

bench_constprop_early_termination

johnzl-777 and others added 4 commits April 3, 2026 14:43
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11499 10336 90% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/kirin/dialects/scf/constprop.py 91% 🟢
TOTAL 91% 🟢

updated for commit: 09a4c72 by action🐍

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

PR Preview Action v1.8.1

QR code for preview link

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

Built to branch gh-pages at 2026-04-03 19:50 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@johnzl-777 johnzl-777 self-assigned this Apr 3, 2026
@johnzl-777 johnzl-777 added Perf-Optimization Performance: Issues and PRs related to performance optimizations. category: enhancement Category: this is an enhancement of an existing feature. area: dialect SCF Area: structural control flow related issues. labels Apr 3, 2026
@johnzl-777 johnzl-777 marked this pull request as ready for review April 3, 2026 19:51
@johnzl-777 johnzl-777 requested a review from weinbe58 April 3, 2026 19:51
@Roger-luo Roger-luo added the area: compiler pass Area: compiler pass related issues. label Apr 7, 2026
Copy link
Copy Markdown
Member

@weinbe58 weinbe58 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler pass Area: compiler pass related issues. area: dialect SCF Area: structural control flow related issues. backport 0.22 category: enhancement Category: this is an enhancement of an existing feature. Perf-Optimization Performance: Issues and PRs related to performance optimizations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants