Conversation
Short-circuit boolean chains (`if b0 or b1 or ... or bN:`) previously threaded every live copyable value through the Input/Output signature of every CFG basic block, even blocks that neither read nor write it. For W booleans across W DataflowBlocks this is O(W^2) total signature width, which drives O(W^2) LLVM insertvalue/extractvalue packing and makes superlinear LLVM passes blow up. For a copyable scalar value whose single definition strictly dominates all its uses, drop it from the signatures of intervening blocks and instead let hugr wire a non-local Dom edge from the defining block directly to the use blocks. Linear/non-copyable values stay threaded (can't be duplicated). - cfg/analysis.py: add iterative dominators (`compute_dominators`), `reverse_postorder`, and natural-loop detection (`loop_blocks`). - cfg_compiler.py: `compute_dethread_info` + `DethreadInfo`; strict single-def-dominates-all-uses gate; RPO block ordering so a def compiles before its uses; supply/store de-threaded wires in `compile_bb`. `Measurement` is explicitly excluded: it is a future that guppy auto-copies at the surface level but Hugr models as linear, so the Helios QIS lowering rejects it on a non-local edge. Tracked as an edge case (TODO) rather than a general type restriction. Payoff on a bool or-chain (W=8/16/32/48): block-signature sum 28/120/496/1128 -> 0; insertvalue 21/105/465/1081 -> 0; extractvalue 35/135/527/1175 -> 0; alloca O(W^2) -> O(W). End-to-end opt-2 compile of a 16x if-chain over 48 measured bools: 20.0s -> 2.2s. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## ss2165-revert-962-poc-current-stack #2091 +/- ##
=======================================================================
+ Coverage 93.21% 93.22% +0.01%
=======================================================================
Files 152 152
Lines 14676 14848 +172
=======================================================================
+ Hits 13680 13842 +162
- Misses 996 1006 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2090.
Copyable values live across CFG blocks but only used past a dominating block were threaded through every intervening block signature — O(W²) in the width of e.g. an
if a or b or ...:chain, which blows up LLVM (SLP/SCCP) to ~90min compiles in the worst cases.Emit a non-local Dom edge from the defining block instead, gated on a strict single-def-dominates-all-uses check (linear, multi-def and loop-carried values stay threaded). Block-signature width goes O(W²)→O(W); on a 16×
if/ 48-bool repro opt-2 compile drops 20s→2.2s.Measurementis carved out — it's future-like and the Helios QIS lowers it to a linear type, which can't ride a non-local edge. Tracked in Quantinuum/tket2#1883.