MLIR pattern checks failing
@fabianschuiki, @maerhart and I noticed while debugging some conversion that adding the flag -DMLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=ON to a CIRCT LLVM build exposes several places where our passes are using the MLIR rewriter/pattern API invalidly.
Running ninja check-circt produces failures on the following tests:
CIRCT :: Conversion/ArcToLLVM/lower-arc-to-llvm.mlir
CIRCT :: Conversion/CombToArith/comb-to-arith.mlir
CIRCT :: Conversion/ConvertToArcs/convert-to-arcs.mlir
CIRCT :: Conversion/HWToLLVM/convert_aggregates.mlir
CIRCT :: Conversion/LoopScheduleToCalyx/convert_pipeline.mlir
CIRCT :: Conversion/LoopScheduleToCalyx/pipeline_register_pass.mlir
CIRCT :: Conversion/SCFToCalyx/cider_source_location.mlir
CIRCT :: Conversion/SCFToCalyx/convert_controlflow.mlir
CIRCT :: Conversion/SCFToCalyx/convert_func.mlir
CIRCT :: Conversion/SCFToCalyx/convert_memory.mlir
CIRCT :: Conversion/SCFToCalyx/convert_simple.mlir
CIRCT :: Conversion/SCFToCalyx/errors.mlir
CIRCT :: Conversion/SCFToCalyx/float_compare.mlir
CIRCT :: Conversion/SCFToCalyx/write_memory.mlir
CIRCT :: Dialect/Arc/arc-canonicalizer.mlir
CIRCT :: Dialect/Arc/canonicalizers.mlir
CIRCT :: Dialect/Arc/lower-sim.mlir
CIRCT :: Dialect/Calyx/affine-ploop-unparallelize.mlir
CIRCT :: Dialect/Calyx/canonicalization.mlir
CIRCT :: Dialect/FIRRTL/canonicalization.mlir
CIRCT :: Dialect/LLHD/Canonicalization/processes.mlir
CIRCT :: Transforms/memory_banking.mlir
CIRCT :: Transforms/memory_banking_attrs.mlir
CIRCT :: Transforms/memory_banking_multi_config.mlir
CIRCT :: Transforms/memory_banking_multi_dim.mlir
CIRCT :: arcilator/arcilator.mlir
CIRCT :: arcilator/compreg.mlir
CIRCT :: arcilator/emit-values.mlir
We could add something like this to nightly CI, similar to our Valgrind runs. Maybe even with a split where we require the known-good tests to pass, and a second run that may fail where we run all the tests, such that we have some documentation of which conversions violate MLIR invariants.
several places where our passes are using the MLIR rewriter/pattern API invalidly.
If you're referring to the DialectConversion strictness checks that are off by default (LLVM ERROR: pattern 'PartialLowerRegion' rollback of IR modifications requested). I tried this locally and filed some issues. Trying to dig them up, but here is one, with some more explanation about this issue:
https://github.com/llvm/circt/issues/8538
We might need to handle this old one as well:
https://github.com/llvm/circt/issues/6795
Just looking at the list of failures, I suspect most of the rest are also (soon to be) invalid uses of the DialectConversion framework.
As I mentioned in the ODM, there are also failures in greedy rewrite patterns (used with the greedy rewriter). E.g., the memory banking pass, the Calyx canonicalizer, and possibly more fail with LLVM ERROR: IR failed to verify after pattern application indicating that the IR is invalid inbetween pattern applications but somehow end up in a valid state once the pass is done.
The FIRRTL canonicalizer test failed with LLVM ERROR: pattern returned failure but IR did change and there are also several tests failing with LLVM ERROR: expected pattern to replace the root operation or modify it in place
I think there is an issue upstream with that debug flag. When allowPatternRollback=false is set for a pass, it does not check for root operation replacement or in-place modification before printing LLVM ERROR: expected pattern to replace the root operation or modify it in place. When ignoring those cases, we're down to
CIRCT :: Conversion/LoopScheduleToCalyx/convert_pipeline.mlir
CIRCT :: Conversion/LoopScheduleToCalyx/pipeline_register_pass.mlir
CIRCT :: Conversion/SCFToCalyx/cider_source_location.mlir
CIRCT :: Conversion/SCFToCalyx/convert_controlflow.mlir
CIRCT :: Conversion/SCFToCalyx/convert_func.mlir
CIRCT :: Conversion/SCFToCalyx/convert_memory.mlir
CIRCT :: Conversion/SCFToCalyx/convert_simple.mlir
CIRCT :: Conversion/SCFToCalyx/errors.mlir
CIRCT :: Conversion/SCFToCalyx/float_compare.mlir
CIRCT :: Conversion/SCFToCalyx/write_memory.mlir
CIRCT :: Dialect/Arc/arc-canonicalizer.mlir
CIRCT :: Dialect/Calyx/affine-ploop-unparallelize.mlir
CIRCT :: Dialect/Calyx/canonicalization.mlir
CIRCT :: Transforms/memory_banking.mlir
CIRCT :: Transforms/memory_banking_attrs.mlir
CIRCT :: Transforms/memory_banking_multi_config.mlir
CIRCT :: Transforms/memory_banking_multi_dim.mlir