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

[Comb] or(concat, concat) -> concat & or(and, concat) -> concat(extract) canonicalizer #8260

Open
maerhart opened this issue Feb 20, 2025 · 2 comments
Labels
Comb Involving the `comb` dialect enhancement New feature or request

Comments

@maerhart
Copy link
Member

maerhart commented Feb 20, 2025

If I'm reading this right, there could be a set of comb canonicalizers doing the following simplification from

  hw.module @alias(in %init : i4, in %in0 : i1, in %in1 : i1, out out : i4) {
    %c0_i2 = hw.constant 0 : i2
    %false = hw.constant false
    %c-5_i4 = hw.constant -5 : i4
    %c-3_i4 = hw.constant -3 : i4
    %c0_i3 = hw.constant 0 : i3
    %c-2_i4 = hw.constant -2 : i4
    %0 = comb.and %init, %c-2_i4 : i4
    %1 = comb.concat %c0_i3, %in1 : i3, i1
    %2 = comb.or %1, %0 : i4
    %3 = comb.and %2, %c-3_i4 : i4
    %4 = comb.concat %c0_i2, %in0, %false : i2, i1, i1
    %5 = comb.or %4, %3 : i4
    %6 = comb.and %5, %c-5_i4 : i4
    %7 = comb.concat %false, %in1, %c0_i2 : i1, i1, i2
    %8 = comb.or %7, %6 : i4
    hw.output %8 : i4
  }

to

  hw.module @alias(in %init : i4, in %in0 : i1, in %in1 : i1, out out : i4) {
    %0 = comb.extract %init from 3 : (i4) -> i1
    %1 = comb.concat %0, %in1, %in0, %in1 : i1, i1, i1, i1
    hw.output %1 : i4
  }
@maerhart maerhart added Comb Involving the `comb` dialect enhancement New feature or request labels Feb 20, 2025
@uenoku
Copy link
Member

uenoku commented Feb 20, 2025

circt-lec says it's not equivalent 🤔

@maerhart
Copy link
Member Author

Oh sorry, I just noticed I had the lowBit attribute of the comb.extract wrong. Now circt-lec is happy (I updated the code above). Thanks for checking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Comb Involving the `comb` dialect enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants