llvm / Polygeist

C/C++ frontend for MLIR. Also features polyhedral optimizations, parallel optimizations, and more!
https://polygeist.llvm.org
Other
478 stars 113 forks source link

'arith.muli' op requires the same type for all operands and results #334

Open Kuree opened 1 year ago

Kuree commented 1 year ago

Here is a minimal reproducible code:

#include <stdint.h>

void foo(uint16_t *a, uint16_t len) {
    uint16_t c = 1;
    for (uint16_t i = 0; i < len; i++) {
        c *= a[i];
        a[i] = c;
    }
}
  "func.func"() ({
  ^bb0(%arg0: memref<?xi16>, %arg1: i16):
    %0 = "arith.constant"() {value = 0 : index} : () -> index
    %1 = "arith.constant"() {value = 1 : index} : () -> index
    %2 = "arith.constant"() {value = 1 : i16} : () -> i16
    %3 = "arith.index_cast"(%arg1) : (i16) -> index
    %4 = "scf.for"(%0, %3, %1, %2) ({
    ^bb0(%arg2: index, %arg3: i16):
      %5 = "memref.load"(%arg0, %arg2) : (memref<?xi16>, index) -> i16
      %6 = "arith.extsi"(%5) : (i16) -> i32
      %7 = "arith.muli"(%arg3, %6) : (i16, i32) -> i16
      "memref.store"(%7, %arg0, %arg2) : (i16, memref<?xi16>, index) -> ()
      "scf.yield"(%7) : (i16) -> ()
    }) : (index, index, index, i16) -> i16
    "func.return"() : () -> ()
  }) {function_type = (memref<?xi16>, i16) -> (), llvm.linkage = #llvm.linkage<external>, sym_name = "foo"} : () -> ()

arith.extsi is unnecessary and actually triggers the error.

susavlsh10 commented 3 weeks ago

were you able to solve this?