cornell-zhang/hcl-dialect

[BUG] FixedType comparison cannot be lowered by FixedPointToInteger pass

Closed this issue · 0 comments

See the following example.

module {
  func.func @kernel(%arg0: !hcl.Fixed<8, 3>) -> i32 attributes {itypes = "s", otypes = "s"} {
    %alloc = memref.alloc() {name = "B"} : memref<1x!hcl.Fixed<8, 3>>
    %c0_i32 = arith.constant 0 : i32
    %0 = hcl.int_to_fixed(%c0_i32) : i32 -> !hcl.Fixed<8, 3>
    affine.store %0, %alloc[0] {to = "B"} : memref<1x!hcl.Fixed<8, 3>>
    %1 = affine.load %alloc[0] {from = "B"} : memref<1x!hcl.Fixed<8, 3>>
    %2 = hcl.cmp_fixed ugt, %arg0, %1 : !hcl.Fixed<8, 3>
    %3 = hcl.fixed_to_fixed(%arg0) : !hcl.Fixed<8, 3> -> !hcl.Fixed<35, 3>
    %c0_i32_0 = arith.constant 0 : i32
    %4 = hcl.int_to_fixed(%c0_i32_0) : i32 -> !hcl.Fixed<35, 3>
    %5 = hcl.cmp_fixed ugt, %3, %4 : !hcl.Fixed<35, 3>
    %6 = arith.andi %2, %5 : i1
    scf.if %6 {
      affine.store %arg0, %alloc[0] {to = "B"} : memref<1x!hcl.Fixed<8, 3>>
    }
    %7 = affine.load %alloc[0] {from = "B"} : memref<1x!hcl.Fixed<8, 3>>
    %8 = hcl.fixed_to_int(%7) : !hcl.Fixed<8, 3> -> i32
    return %8 : i32
  }
}

It will give an error:

castIntegerWidth: input is not integer type, input value is: <block argument> of type '!hcl.Fixed<8, 3>' at index: 0
python3: /scratch/users/hc676/heterocl/hcl-dialect/lib/Conversion/FixedPointToInteger.cpp:36: mlir::Value mlir::hcl::castIntegerWidth(mlir::MLIRContext*, mlir::OpBuilder&, mlir::Location, mlir::Value, size_t, bool): Assertion `false' failed.