Skip to content

Fix MLIR exhaustive control-flow terminators - #756

Merged
godofecht merged 2 commits into
mainfrom
fix/mlir-exhaustive-match-terminators
Aug 23, 2026
Merged

godofecht merged 2 commits into
mainfrom
fix/mlir-exhaustive-match-terminators

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

What

Fix verifier-invalid MLIR produced by nested exhaustive control flow.

  • Treat llvm.unreachable as a real MLIR terminator so enclosing match/if lowering does not append cf.br after it.
  • Use an all-paths return predicate for exhaustive matches instead of the historical any-return helper.
  • Stop lowering dead source statements after an exhaustive-return match/if, so no operations can be emitted after a terminator in the same block.
  • Add regressions for nested exhaustive matches and dead statements after exhaustive returns.

Why

The portable flow-idiomatics corpus exposed this with maximal/algebraic_core.flow: an inner exhaustive match ended in llvm.unreachable, then its enclosing match treated that block as unterminated and appended another operation. LLVM 18 mlir-opt correctly rejected the result with llvm.unreachable op must be the last operation in the parent block.

This fixes the compiler rather than weakening the higher-order/algebraic source program.

@godofecht
godofecht merged commit ed47526 into main Aug 23, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant