llvm / circt

Circuit IR Compilers and Tools

Home Page:https://circt.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Comb][Canonicalize] Missing best effort dialect attribute propagation

7FM opened this issue · comments

commented

Similar to my previous issue #5531, several canonicalizations drop attributes (except sv.namehint). While I agree that it is unsafe to propagate discardable attributes freely, I think that the current implementation might be slightly to conservative.
As @teqdruid pointed out in #5532 (comment):

In general, dialect attributes should be propagated best effort, so I think it's appropriate to propagated them through the canonicalizers where it's obvious what the destination/source op is.

IMHO one such example would be when the canonicalization rewrites the operation without changing the dialect operation class.
Here is an example for the canonicalize pattern extract(olo, extract(ilo, x)) = extract(olo + ilo, x):

module {
  hw.module @attrsGone(in %arg0: i64, out res: i32) {
    %0 = comb.extract %arg0 from 0 : (i64) -> i42
    %1 = comb.extract %0 from 0 {custom_dialect.attr = "test"} : (i42) -> i32
    hw.output %1 : i32
  }
}

Current result after -canonicalize:

module {
  hw.module @attrsGone(in %arg0 : i64, out res : i32) {
    %0 = comb.extract %arg0 from 0 : (i64) -> i32
    hw.output %0 : i32
  }
}

With a best effort propagation:

module {
  hw.module @attrsGone(in %arg0 : i64, out res : i32) {
    %0 = comb.extract %arg0 from 0 {custom_dialect.attr = "test"} : (i64) -> i32
    hw.output %0 : i32
  }
}