Issue 174545
Summary [MLIR]Inconsistent results between `-convert-linalg-to-affine-loops` and `-convert-linalg-to-loops` for `linalg.matmul`
Labels mlir
Assignees
Reporter BealZephyr
    **test commit**: [5cfd02](https://github.com/llvm/llvm-project/commit/5cfd02f44a43a2e2a085a633b022a62f64ba2b93)

## Description:
I encountered an issue with the linalg.matmul operation where the results differ when using two different conversion passes.
`-convert-linalg-to-affine-loops  -lower-affine` produces the expected result.
`-convert-linalg-to-loops` produces an unexpected output, which suggests that the issue is tied to the loop lowering mechanism.

## test case
```
module {
  func.func private @printMemrefI32(tensor<*xi32>)
  func.func @main() {
    %0 = "tosa.const"() <{values = dense<-6.693750e+01> : tensor<16x8xf16>}> : () -> tensor<16x8xf16>
    %1 = "tosa.const"() <{values = dense<-1.133700e+02> : tensor<8x32xf64>}> : () -> tensor<8x32xf64>
    %2 = "tosa.const"() <{values = dense<22> : tensor<16x32xi32>}> : () -> tensor<16x32xi32>
    %3 = linalg.matmul {cast = #linalg.type_fn<cast_unsigned>} ins(%0, %1 : tensor<16x8xf16>, tensor<8x32xf64>) outs(%2 : tensor<16x32xi32>) -> tensor<16x32xi32>
    %cast = tensor.cast %3 : tensor<16x32xi32> to tensor<*xi32>
    call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
 return
  }
}
```

## Command:
### 1. Use `-convert-linalg-to-affine-loops  -lower-affine` 
#### cmd:
```
mlir-opt test.mlir -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries=1" -convert-linalg-to-affine-loops  -lower-affine \
-convert-scf-to-cf -convert-to-llvm |  mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project-latest/build/lib/libmlir_runner_utils.so


```

#### output:
```
[[22,   22,   22,   22,   22,   22,   22,   22,   22,   22, 22,   22,   22,   22,   22,   22,   22, ...]]
```
### 2. Use `-convert-linalg-to-loops`:
#### cmd:
```
mlir-opt test.mlir -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries=1" -convert-linalg-to-loops  \
-convert-scf-to-cf   -convert-to-llvm | mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project-latest/build/lib/libmlir_runner_utils.so


```
#### output:
```
[[30,   30,   30,   30,   30,   30,   30,   30,   30,   30, 30,   30,   30,   30,   30,   30,   30,  ...]]
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to