llvm / llvm/circt

[SV] Miss-complication by reordering side-effect ops

Open
#3,028 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

```mlir
hw.module @Foo(%clock:i1, %a:i8, %b:i8) {
%reg = sv.reg : !hw.inout
%fd = hw.constant 0x80000002 : i32
sv.always posedge %clock {
sv.bpassign %reg, %a : i8
%x = sv.read_inout %reg : !hw.inout
sv.bpassign %reg, %b : i8
sv.fwrite %fd, "%d"(%x) : i8
}
}
```

Current output:
```verilog
module Foo(
input clock,
input [7:0] a,
b);

reg [7:0] reg_0;

always @(posedge clock) begin
reg_0 = a;
reg_0 = b;
$fwrite(32'h80000002, "%d", reg_0);
end // always @(posedge)
endmodule
```

This is incorrect because the value of `a` should be printed. I guess we have to create a temporary register if we can't use `automatic`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the MLIR example with the SystemVerilog operations sv.bpassign, sv.read_inout, and sv.fwrite, then trace the SystemVerilog emission for this always block. Done means the generated Verilog preserves the value assigned from a before the later assignment from b, so the fwrite prints a.

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
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.