cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
37 stars 17 forks source link

Unary integer negation converted to float #149

Closed jcasas00 closed 1 year ago

jcasas00 commented 1 year ago
    def kernel():
        a = hcl.scalar(1, "a", dtype='int32')
        t = -a.v 

fails as the negation uses arith.negf which expects a float:

"builtin.module"() ({
  "func.func"() ({
    %0 = "arith.constant"() {value = 0 : index} : () -> index
    %1 = "memref.alloc"() {name = "a", operand_segment_sizes = dense<0> : vector<2xi32>} : () -> memref<1xi32>
    %2 = "arith.constant"() {value = 0 : index} : () -> index
    %3 = "arith.constant"() {value = 1 : i32} : () -> i32
    "affine.store"(%3, %1) {map = #map0, to = "a"} : (i32, memref<1xi32>) -> ()
    %4 = "affine.load"(%1) {from = "a", map = #map0} : (memref<1xi32>) -> i32
    %5 = "arith.negf"(%4) : (i32) -> i32
    ...

error: 'arith.negf' op operand #0 must be floating-point-like, but got 'i32'
zzzDavid commented 1 year ago

The arithmetic dialect in MLIR does not have arith.negi (weird that they still don't have it in LLVM15). I'll build an arith.muli %cst-1 %rhs for this case.

jcasas00 commented 1 year ago

My workaround was to do 0-i. But yeah, weird that there's no arith.negi .

zzzDavid commented 1 year ago

Negation has been implemented in IRBuilder, a test for negation data type is added by cornell-zhang/heterocl@3ceca236bdd8421095f14e6eead01275403c537c