llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.31k stars 12.11k forks source link

[mlir] Inconsistent results for affine.apply #114654

Open wangyongj1a opened 3 weeks ago

wangyongj1a commented 3 weeks ago

I have the following MLIR program: test.mlir:

#map2 = affine_map<(d0, d1) -> (((d1 - (d1 + 2)) floordiv 8) mod 8)>

module {
  func.func nested @func1() -> f32 {
    %idx1 = arith.constant 1 : index
    %res2 = affine.apply #map2(%idx1, %idx1)
    vector.print %res2 : index
    %0 = arith.index_cast %res2 : index to i64
    %1 = arith.sitofp %0 : i64 to f32
    return %1 : f32
  }
}

When I ran /data/tmp/v1102/llvm-project/build/bin/mlir-opt --lower-affine --convert-arith-to-llvm --convert-vector-to-llvm --convert-func-to-llvm --convert-index-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so on the program, I got the result of:

7
7.000000e+00

However, when I ran /data/tmp/v1102/llvm-project/build/bin/mlir-opt --affine-simplify-structures --lower-affine --convert-arith-to-llvm --convert-vector-to-llvm --convert-func-to-llvm --convert-index-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so on the program, I got the result of:

8
8.000000e+00

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 33bdb53d864e3e244d8fd5649062f17b7d4c958d.

llvmbot commented 3 weeks ago

@llvm/issue-subscribers-mlir-affine

Author: None (wangyongj1a)

I have the following MLIR program: test.mlir: ``` #map2 = affine_map<(d0, d1) -> (((d1 - (d1 + 2)) floordiv 8) mod 8)> module { func.func nested @func1() -> f32 { %idx1 = arith.constant 1 : index %res2 = affine.apply #map2(%idx1, %idx1) vector.print %res2 : index %0 = arith.index_cast %res2 : index to i64 %1 = arith.sitofp %0 : i64 to f32 return %1 : f32 } } ``` When I ran ```/data/tmp/v1102/llvm-project/build/bin/mlir-opt --lower-affine --convert-arith-to-llvm --convert-vector-to-llvm --convert-func-to-llvm --convert-index-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of: ``` 7 7.000000e+00 ``` However, when I ran ```/data/tmp/v1102/llvm-project/build/bin/mlir-opt --affine-simplify-structures --lower-affine --convert-arith-to-llvm --convert-vector-to-llvm --convert-func-to-llvm --convert-index-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of: ``` 8 8.000000e+00 ``` 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 33bdb53d864e3e244d8fd5649062f17b7d4c958d.
bondhugula commented 1 week ago

Is simplify-affine-structures the only difference between the two runs? (I couldn't immediately tell.) 7 is the right answer here and there appears to be a bug exposed by the second pipeline.