llvm / llvm/circt

[ExportVerilog] Unnecessary temporary wire for bitcast op used only by concat

Open
#4,472 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

input:
```mlir
hw.module @casts(%in1: i7, %in2: !hw.array<8xi4>) -> (out: i39) {
%r2 = hw.bitcast %in2 : (!hw.array<8xi4>) -> i32
%0 = comb.concat %in1, %r2: i7, i32

hw.output %0 : i39
}
```
current output:
```verilog
module casts( // foo.mlir:1:1
input [6:0] in1,
input [7:0][3:0] in2,
output [38:0] out);

wire [31:0] _GEN = /*cast(bit[31:0])*/in2; // foo.mlir:2:9
assign out = {in1, _GEN}; // foo.mlir:2:9, :3:8, :5:3
endmodule
````

We can remove `_GEN` if `_GEN` is used only by concat.

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

Start in the ExportVerilog handling for hw.bitcast and comb.concat, using the MLIR example and generated Verilog in this issue as the reproduction. Trace the temporary wire decision when the bitcast result has only a concat use, then verify that the output contains the cast inline without _GEN while preserving the expected 39-bit concatenation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.