<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/126195>126195</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent results when using --int-range-optimizations
        </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 @main() -> i64 {
    %idx9 = index.constant 9
    %idx11 = index.constant 11
    %idx0 = index.constant 0
    %0 = llvm.mlir.constant(true) : i1
 %1 = llvm.mlir.constant(29 : index) : i64
    %2 = builtin.unrealized_conversion_cast %1 : i64 to index
    %false = index.bool.constant false
    cf.cond_br %false, ^bb1, ^bb2
  ^bb1:  // pred: ^bb0
    cf.br ^bb3(%2 : index)
  ^bb2:  // pred: ^bb0
    cf.br ^bb3(%idx9 : index)
  ^bb3(%3: index):  // 2 preds: ^bb1, ^bb2
    cf.br ^bb4
  ^bb4:  // pred: ^bb3
    vector.print %3 : index
    cf.cond_br %false, ^bb5, ^bb6
  ^bb5:  // pred: ^bb4
    cf.br ^bb7(%2 : index)
 ^bb6:  // pred: ^bb4
    cf.br ^bb7(%idx11 : index)
  ^bb7(%4: index):  // 2 preds: ^bb5, ^bb6
    cf.br ^bb8
  ^bb8:  // pred: ^bb7
    vector.print %4 : index
    cf.cond_br %0, ^bb9, ^bb10
  ^bb9:  // pred: ^bb8
    cf.br ^bb11(%2 : index)
  ^bb10:  // pred: ^bb8
    cf.br ^bb11(%idx0 : index)
 ^bb11(%5: index):  // 2 preds: ^bb9, ^bb10
    cf.br ^bb12
  ^bb12:  // pred: ^bb11
    %6 = builtin.unrealized_conversion_cast %5 : index to i64
 vector.print %5 : index
    return %6 : i64
  }
}
```
When I ran 
```
/data/tmp/v0207/llvm-project/build/bin/mlir-opt \
--convert-arith-to-llvm --convert-vector-to-llvm --convert-index-to-llvm --convert-func-to-llvm --convert-cf-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v0207/llvm-project/build/bin/mlir-runner --entry-point-result=i64 --shared-libs=/data/tmp/v0207/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v0207/llvm-project/build/lib/libmlir_c_runner_utils.so
``` 
on the program, I got the result of:
```
9
11
29
29
```
However, when I ran
 ```
/data/tmp/v0207/llvm-project/build/bin/mlir-opt \
--int-range-optimizations \
--convert-arith-to-llvm --convert-vector-to-llvm --convert-index-to-llvm --convert-func-to-llvm --convert-cf-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v0207/llvm-project/build/bin/mlir-runner --entry-point-result=i64 --shared-libs=/data/tmp/v0207/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v0207/llvm-project/build/lib/libmlir_c_runner_utils.so
``` 
on the program, I sometimes got the result of:
```
9
11
9
9
```
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 4d3148d92681c154de51379a0cf393f9af8e1d75.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsV1GPozYQ_jXOywgENg7hIQ-5zUWN1HupKvVxZcAQn8CObJNc7tdXNgTIJundbvtUnbRLYDyez9_MeMZmxohacr5G9BOi2wXr7EHp9ZnJ-qJk_TVmi1yVl_UeDuzEwR44VKpp1FnIGr78vv8DjlrVmrWIbFC0sdzYsG2E7j_RMhr-ok2ryq7hgNJPKNoAVJ0sQvcAlEQtExLhFcIZBIh8BrFMRkUAhKkov2WAyBaELPm3sFDSWCYtZDcqcfxIJ45vlKJHOtGk0o83zan1REYdhFdWd9ytEZENCG8VYRo_17-qOqxx3jKZsLCfm3eisUKGndScNeI7L18LJU9cG6Hka8GMveL46WDVYHK0U7HG8BmvXKlmIudHB-WicvLyNdfjPIRfANHPeR6Pb9hrD0LiXvEO4R0cNS_dtx-JJ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