llvm / llvm/circt

[FIRRTL] SizeOf intrinsic requires optimizations enabled to successfully lower

Open
#11,064 1 comment 0 reactions 0 assignees View on GitHub
FIRRTL
Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

```firrtl
FIRRTL version 4.0.0
circuit Top:
public module Top:
output size: UInt<32>
wire empty: {nested: {zero: UInt<1>[0]}}
node sizeNode = intrinsic(circt_sizeof : UInt<32>, empty)
connect size, sizeNode
```

With normal optimization enabled, this succeeds because canonicalization folds the intrinsic to `UInt<32>(0)`:

```text
module Top(
output [31:0] size
);

assign size = 32'h0;
endmodule
```

Running `firtool input.fir --disable-opt ` where optimization is disabled, the intrinsic remains in the IR and `LowerToHW`
reports:

```text
test.fir:6:21: error: SizeOf should have been resolved.
node sizeNode = intrinsic(circt_sizeof : UInt<32>, empty)
^
test.fir:6:21: note: see current operation: %6 = "firrtl.int.sizeof"(%5) : (!firrtl.bundle, 0>>>) -> !firrtl.uint<32>
test.fir:6:21: error: 'firrtl.int.sizeof' op LowerToHW couldn't handle this operation
node sizeNode = intrinsic(circt_sizeof : UInt<32>, empty)
^
test.fir:6:21: note: see current operation: %6 = "firrtl.int.sizeof"(%5) : (!firrtl.bundle, 0>>>) -> !firrtl.uint<32>
```

`SizeOfIntrinsicOp` is a compile-time-only operation. Its folder computes the bit width from the operand type; it has no hardware lowering. Therefore, `LowerToHW` requires the canonicalizer to have resolved it first. We should be able to successfully compile this without optimizations.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the FIRRTL input and `firtool input.fir --disable-opt`. Start at `SizeOfIntrinsicOp` and its folder, then inspect the `LowerToHW` entry point to determine how unresolved SizeOf operations are handled. Done means the example compiles successfully with optimizations disabled and produces the expected zero-valued output.

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
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.