[FSM] Eliminate mutually exclusive transition guards (#3577)#10754
Open
arefinaa wants to merge 1 commit into
Open
[FSM] Eliminate mutually exclusive transition guards (#3577)#10754arefinaa wants to merge 1 commit into
arefinaa wants to merge 1 commit into
Conversation
When a state has exactly two outgoing transitions whose guards are logical complements of one another (e.g. `cond` and `!cond`), the second transition is only reached when the first guard has already failed, which implies the second guard necessarily holds. The second guard is therefore redundant. This adds a canonicalization to `StateOp::canonicalize` that detects this case and strips the second transition's guard, turning it into an unconditional default transition. The complement is recognized in both the comb (`comb.xor %cond, %true`) and arith (`arith.xori %cond, %true`) spellings; the now-dead complement op is removed by dead-code elimination. This removes redundant logic that the Calyx -> FSM lowering emits verbatim and that would otherwise propagate all the way to emitted SystemVerilog. The pattern is conservatively scoped to states with exactly two transitions to avoid the non-determinism that affected earlier unreachable-state work. Adds lit tests covering the comb and arith positive cases and negative cases (non-complementary guards, and a three-transition state). Assisted-by: Claude Code:claude-opus-4-8 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What does this PR do?
Adds a canonicalization to
fsm.statethat detects when a state has exactlytwo outgoing transitions whose guards are logical complements of one another
(e.g.
condand!cond) and strips the second transition's guard, turning itinto an unconditional default transition. Since the second transition is only
reached when the first guard has already failed, the second guard necessarily
holds and is redundant. The complement is recognized in both the comb
(
comb.xor %cond, %true) and arith (arith.xori %cond, %true) spellings.Why was this PR needed?
The Calyx → FSM lowering emits these mutually exclusive guard pairs verbatim,
and the redundant logic propagates all the way into the emitted SystemVerilog.
The pattern is conservatively scoped to states with exactly two transitions to
avoid the non-determinism that affected earlier unreachable-state work on this
issue.
What are the relevant issue numbers?
Fixes #3577
Testing
test/Dialect/FSM/canonicalize.mlir: positive casesfor both comb and arith complement spellings, and negative cases
(non-complementary guards, three-transition state)
Assisted-by: Claude Code:claude-opus-4-8