<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112878>112878</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Inconsistent results for linalg.transpose
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangyongj1a
</td>
</tr>
</table>
<pre>
I have the following MLIR program:
test.mlir:
```
module {
func.func @func1() -> f32 {
%true = arith.constant true
%c-4534883404942705875_i64 = arith.constant -4534883404942705875 : i64
%c-30978575762189800_i64 = arith.constant -30978575762189800 : i64
%c-169620577492_i64 = arith.constant -169620577492 : i64
%c-63283138746_i64 = arith.constant -63283138746 : i64
%from_elements = tensor.from_elements %c-4534883404942705875_i64, %c-30978575762189800_i64, %c-169620577492_i64, %c-63283138746_i64 : tensor<2x2xi64>
%cast = tensor.cast %from_elements : tensor<2x2xi64> to tensor<?x?xi64>
%4 = scf.if %true -> (tensor<?x?xi64>) {
scf.yield %cast : tensor<?x?xi64>
} else {
scf.yield %cast : tensor<?x?xi64>
}
%transposed = linalg.transpose ins(%4 : tensor<?x?xi64>) outs(%cast : tensor<?x?xi64>) permutation = [1, 0]
%collapsed_8 = tensor.collapse_shape %cast [[0, 1]] : tensor<?x?xi64> into tensor<?xi64>
%collapsed_10 = tensor.collapse_shape %transposed [[0, 1]] : tensor<?x?xi64> into tensor<?xi64>
%idx0 = index.constant 0
%idx1 = index.constant 1
%idx2 = index.constant 2
%idx3 = index.constant 3
%extracted0 = tensor.extract %collapsed_10[%idx0] : tensor<?xi64>
vector.print %extracted0 : i64
%extracted1 = tensor.extract %collapsed_10[%idx1] : tensor<?xi64>
vector.print %extracted1 : i64
%extracted2 = tensor.extract %collapsed_10[%idx2] : tensor<?xi64>
vector.print %extracted2 : i64
%extracted3 = tensor.extract %collapsed_10[%idx3] : tensor<?xi64>
vector.print %extracted3 : i64
%111 = arith.sitofp %extracted2 :i64 to f32
return %111 : f32
}
}
```
When I ran ```/data/tmp/v1018/llvm-project/build/bin/mlir-opt --one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" --convert-index-to-llvm --convert-linalg-to-loops --convert-vector-to-llvm --expand-strided-metadata --convert-scf-to-cf --lower-affine --one-shot-bufferize="dialect-filter=tensor" --func-bufferize --one-shot-bufferize="dialect-filter=arith" --convert-arith-to-llvm --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1018/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1018/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1018/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
-4534883404942705875
-169620577492
-30978575762189800
-63283138746
-3.097857e+16
```
However, when I ran ```/data/tmp/v1018/llvm-project/build/bin/mlir-opt --linalg-generalize-named-ops --one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" --convert-index-to-llvm --convert-linalg-to-loops --convert-vector-to-llvm --expand-strided-metadata --convert-scf-to-cf --lower-affine --one-shot-bufferize="dialect-filter=tensor" --func-bufferize --one-shot-bufferize="dialect-filter=arith" --convert-arith-to-llvm --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1018/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1018/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1018/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
-4534883404942705875
-169620577492
-169620577492
-63283138746
-1.696206e+11
```
The above two results seem to be inconsistent. I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused these results.
My git version is 18ac0178ad7f839bdb3376b7a0c6b69a24520a06.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWF9vqzoS_zTOywiEbf4-5KFtbrSV9r6sVtrHysCQ-ArsyDZpej79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