Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MooreToCore] moore.extract is converted to hw.array_slice when array's element type is also array #7918

Open
slowlime opened this issue Nov 28, 2024 · 0 comments

Comments

@slowlime
Copy link
Contributor

Given this module:

module {
  moore.module @test(out x : !moore.l4) {
    %arr = moore.variable : <array<2 x array<3 x l4>>>
    %0 = moore.read %arr : <array<2 x array<3 x l4>>>
    %1 = moore.extract %0 from 1 : array<2 x array<3 x l4>> -> array<3 x l4>
    %2 = moore.extract %1 from 2 : array<3 x l4> -> l4
    moore.output %2 : !moore.l4
  }
}

Here is the result of running MooreToCore:

module {
  hw.module @test(out x : i4) {
    %c0_i24 = hw.constant 0 : i24
    %0 = hw.bitcast %c0_i24 : (i24) -> !hw.array<2xarray<3xi4>>
    %arr = llhd.sig %0 : !hw.array<2xarray<3xi4>>
    %1 = llhd.prb %arr : !hw.inout<array<2xarray<3xi4>>>
    %true = hw.constant true
    %2 = hw.array_slice %1[%true] : (!hw.array<2xarray<3xi4>>) -> !hw.array<3xi4>
    %c-2_i2 = hw.constant -2 : i2
    %3 = hw.array_get %2[%c-2_i2] : !hw.array<3xi4>, i2
    hw.output %3 : i4
  }
}

It can be seen that %1 = moore.extract ... was translated to %2 = hw.array_slice ...: moore.extract's result type is an array, so it was mistaken for a slicing operation.

The resulting module is malformed and fails validation after canonicalization (due to hw.output's argument not matching the output port's type).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant