Issue 137281
Summary [mlir] Inconsistent output when executing MLIR program with `--int-range-optimizations`
Labels mlir
Assignees
Reporter Emilyaxe
    git version: f0c61d2242bbc7576ca5e4137a5ea8f63e4859a9

system: `Ubuntu 18.04.6 LTS`

## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without `--int-range-optimizations`. 


## Steps to Reproduce:

### 1. **MLIR Program (a.mlir)**:
a.mlir: 
``` 
module {
  func.func @main() {
    %false = arith.constant false
 %c8_i32 = arith.constant 8 : i32
    %20 = arith.trunci %c8_i32 : i32 to i6
    %35 = arith.constant 35 : i63
    %36 = arith.constant 36 : i64
 %sum_2, %overflow_3 = arith.addui_extended %false, %false : i1, i1
 cf.cond_br %false, ^bb1, ^bb2
  ^bb1:  // pred: ^bb0
    cf.br ^bb3(%35, %36, %20 : i63, i64, i6)
  ^bb2:  // pred: ^bb0
    %c4_i64 = arith.constant 4 : i64
    cf.br ^bb3(%35, %c4_i64, %20 : i63, i64, i6)
 ^bb3(%73: i63, %74: i64, %75: i6):  // 2 preds: ^bb1, ^bb2
    cf.br ^bb4
 ^bb4:  // pred: ^bb3
    cf.cond_br %sum_2, ^bb5, ^bb6
  ^bb5:  // pred: ^bb4
    %c-7668919674129928000_i64 = arith.constant -7668919674129928000 : i64
    cf.br ^bb7(%c-7668919674129928000_i64 : i64)
  ^bb6:  // pred: ^bb4
    %c52_i64 = arith.constant 52 : i64
    cf.br ^bb7(%c52_i64 : i64)
  ^bb7(%76: i64):  // 2 preds: ^bb5, ^bb6
    cf.br ^bb8
  ^bb8:  // pred: ^bb7
    vector.print str "%266="
    vector.print %76 : i64
 return
  }
}


``` 

 ### 2. **Command to Run without `--int-range-optimizations` :**

``` 
/data/szy/workspace/llvm-release/llvm-project/build/bin/mlir-opt /data/szy/workspace/mlir-inconsistent/a.mlir   \
-convert-arith-to-llvm -convert-vector-to-llvm  -convert-arith-to-llvm  -convert-cf-to-llvm \
-convert-func-to-llvm  -reconcile-unrealized-casts \
| timeout 10 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main \
-entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so

``` 

### 3. **Output  without  `--int-range-optimizations` :**:

``` 
%266=52
``` 

### 4. **Command to Run with  `--int-range-optimizations` :**


``` 
/data/szy/workspace/llvm-release/llvm-project/build/bin/mlir-opt /data/szy/workspace/mlir-inconsistent/a.mlir  \
--int-range-optimizations -convert-arith-to-llvm   -convert-vector-to-llvm  -convert-arith-to-llvm \
-convert-cf-to-llvm  -convert-func-to-llvm  -reconcile-unrealized-casts \
| timeout 10 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main \
-entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so

``` 

### 5. **Output with `--int-range-optimizations` :**

``` 
%266=4
``` 

### 6. **Analysis for this case :**

After running with `--int-range-optimizations`, a.mlir becomes as follows:
It directly returns %c4_i64 (4)

```
module {
  func.func @main() {
    %c4_i64 = arith.constant 4 : i64
    %false = arith.constant false
    cf.cond_br %false, ^bb1, ^bb1
  ^bb1:  // 2 preds: ^bb0, ^bb0
    cf.br ^bb2
  ^bb2: // pred: ^bb1
    cf.br ^bb3
  ^bb3:  // pred: ^bb2
    cf.cond_br %false, ^bb4, ^bb4
  ^bb4:  // 2 preds: ^bb3, ^bb3
    cf.br ^bb5
  ^bb5:  // pred: ^bb4
    cf.br ^bb6
  ^bb6:  // pred: ^bb5
    vector.print str "%266="
    vector.print %c4_i64 : i64
    return
  }
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to