Skip to content

ConstProp early termination optimization#632

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

ConstProp early termination optimization#632
johnzl-777 wants to merge 6 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
11452 10286 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: 582bd7f 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 structural control flow related issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dialect SCF structural control flow related issue 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.

1 participant