llvm / llvm/circt

[Comb] Concat/extract canonicalizer crashes on loop

Open
#8,863 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Comb
Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

Consider the following input:
```mlir
hw.module @Foo(in %a : i1, in %b : i1, out z : i4) {
%0 = comb.extract %1 from 2 : (i4) -> i2
%1 = comb.concat %0, %b, %a : i2, i1, i1
hw.output %1 : i4
}
```
Running this through `circt-opt --canonicalize` crashes:
```
Assertion `op->use_empty() && "expected 'op' to have no uses"' failed.
[...]
#8 mlir::RewriterBase::eraseOp(mlir::Operation*)
#9 mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::ValueRange)
#10 circt::replaceOpAndCopyNamehint(mlir::PatternRewriter&, mlir::Operation*, mlir::Value)
#11 extractConcatToConcatExtract(circt::comb::ExtractOp, circt::comb::ConcatOp, mlir::PatternRewriter&)
/home/fabian/code/circt/lib/Dialect/Comb/CombFolds.cpp:513:3
#12 circt::comb::ExtractOp::canonicalize(circt::comb::ExtractOp, mlir::PatternRewriter&)
/home/fabian/code/circt/lib/Dialect/Comb/CombFolds.cpp:578:12
```
The input was generate from (loop is useless in practice but intentional):
```systemverilog
module Foo(input logic a, logic b, output logic [3:0] z);
logic [3:0] x;
always_comb begin
x[0] = a;
x[1] = b;
end
assign z = x;
endmodule
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The crash is in lib/Dialect/Comb/CombFolds.cpp, in extractConcatToConcatExtract around line 513, reached from ExtractOp::canonicalize. Run the supplied MLIR through circt-opt --canonicalize and inspect how the concat/extract loop is rewritten and erased. Done means this reproducer no longer asserts, with regression coverage for the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.