llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[MLIR] Inconsistent output when executing MLIR program with and without `-scf-for-loop-peeling=peel-front=true`

Open Lambor24 opened this issue 1 year ago • 2 comments

My git version is 6311e3f.

Description:

I am experiencing an inconsistent result when executing the same MLIR program with and without the -scf-for-loop-peeling=peel-front=true.

Steps to Reproduce:

1. MLIR Program (test.mlir):

test.mlir:

module {
  func.func private @printMemrefF32(tensor<*xf32>)
  func.func @main() {
    %0 = "tosa.const"() <{value = dense<-3.871940e+03> : tensor<3x3xf32>}> : () -> tensor<3x3xf32>
    %1 = tosa.ceil %0 : (tensor<3x3xf32>) -> tensor<3x3xf32>
    %cast = tensor.cast %1 : tensor<3x3xf32> to tensor<*xf32>
    call @printMemrefF32(%cast) : (tensor<*xf32>) -> ()
    return
  }
}

2. Command to Run Without -scf-for-loop-peeling=peel-front=true:

/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -sparsification-and-bufferization -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -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-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 -scf-for-loop-peeling=peel-front=true:

[[-3871,   -3871,   -3871], 
 [-3871,   -3871,   -3871], 
 [-3871,   -3871,   -3871]]

4. Command to Run With -scf-for-loop-peeling=peel-front=true:

/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -sparsification-and-bufferization -convert-linalg-to-affine-loops -lower-affine -scf-for-loop-peeling=peel-front=true -convert-scf-to-cf -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-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 -scf-for-loop-peeling=peel-front=true:

[[-3871,   0,   0], 
 [-3871,   -3871,   -3871], 
 [-3871,   -3871,   -3871]]

I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused this result.

Lambor24 avatar Mar 06 '25 09:03 Lambor24

@llvm/issue-subscribers-mlir

Author: None (Lambor24)

My git version is [6311e3f](https://github.com/llvm/llvm-project/commit/6311e3fcc8539cf0f474b28f82a465e83013a792).

Description:

I am experiencing an inconsistent result when executing the same MLIR program with and without the -scf-for-loop-peeling=peel-front=true.

Steps to Reproduce:

1. MLIR Program (test.mlir):

test.mlir:

module {
  func.func private @<!-- -->printMemrefF32(tensor&lt;*xf32&gt;)
  func.func @<!-- -->main() {
    %0 = "tosa.const"() &lt;{value = dense&lt;-3.871940e+03&gt; : tensor&lt;3x3xf32&gt;}&gt; : () -&gt; tensor&lt;3x3xf32&gt;
    %1 = tosa.ceil %0 : (tensor&lt;3x3xf32&gt;) -&gt; tensor&lt;3x3xf32&gt;
    %cast = tensor.cast %1 : tensor&lt;3x3xf32&gt; to tensor&lt;*xf32&gt;
    call @<!-- -->printMemrefF32(%cast) : (tensor&lt;*xf32&gt;) -&gt; ()
    return
  }
}

2. Command to Run Without -scf-for-loop-peeling=peel-front=true:

/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -sparsification-and-bufferization -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -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-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 -scf-for-loop-peeling=peel-front=true:

[[-3871,   -3871,   -3871], 
 [-3871,   -3871,   -3871], 
 [-3871,   -3871,   -3871]]

4. Command to Run With -scf-for-loop-peeling=peel-front=true:

/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -sparsification-and-bufferization -convert-linalg-to-affine-loops -lower-affine -scf-for-loop-peeling=peel-front=true -convert-scf-to-cf -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-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 -scf-for-loop-peeling=peel-front=true:

[[-3871,   0,   0], 
 [-3871,   -3871,   -3871], 
 [-3871,   -3871,   -3871]]

I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused this result.

llvmbot avatar Mar 06 '25 09:03 llvmbot

This issue has been fixed.

Lambor24 avatar Jan 04 '26 12:01 Lambor24