[MLIR] Inconsistent output when executing MLIR program with and without `-test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`
My git version is 35619c7.
Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control.
The outputs are also inconsistent when running multiple times with the -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control.
Steps to Reproduce:
1. MLIR Program (test.mlir):
test.mlir:
module {
func.func private @printMemrefI32(tensor<*xi32>)
func.func @main() -> () {
%arg0 = "tosa.const"() {value = dense<94> : tensor<i32>} : () -> tensor<i32>
%arg1 = "tosa.const"() {value = dense<91> : tensor<i32>} : () -> tensor<i32>
%0 = tosa.arithmetic_right_shift %arg0, %arg1 {round = true} : (tensor<i32>, tensor<i32>) -> tensor<i32>
%rtn1 = tensor.cast %0 : tensor<i32> to tensor<*xi32>
call @printMemrefI32(%rtn1) : (tensor<*xi32>) -> ()
return
}
}
2. Command to Run Without -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control:
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
3. Output Without -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control:
[0]
4. Command to Run With -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control:
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-tensor -tosa-to-arith -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
5. Output With -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control:
[222542855]
This output is different when executed multiple times.
I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused this result.
Same as https://github.com/llvm/llvm-project/issues/118939, arithmetic right shift by amount greater than bitwidth is UB. In the first case, compiler is not producing poison due to load indirection. In second case, you are seeing poison value.