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

    <tr>
        <th>Summary</th>
        <td>
            Inconsistent results when using --int-range-optimizations
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </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 @func1() {
 %false = arith.constant false
    %c2060639849_i64 = arith.constant 2060639849 : i64

    %c1_i64 = arith.constant 1 : i64
    %c0_i64 = arith.constant 0 : i64

    %36 = scf.if %false -> (i64) {  //the result should be 2060639849
      scf.yield %c1_i64 : i64
    } else {
      scf.yield %c2060639849_i64 : i64
    }
    %37 = arith.divsi %c1_i64, %36 : i64  //the result should be 0

    %41 = arith.addi %c2060639849_i64, %37 : i64  //the result should be 2060639849

    %70 = arith.xori %41, %c2060639849_i64 : i64  //the result should be 0

 %88 = arith.cmpi eq, %70, %c0_i64 : i64  //the result should be true

 %89 = scf.if %88 -> (i64) {  //the result should be 3
      %c3_i64 = arith.constant 3 : i64
      scf.yield %c3_i64 : i64
    } else {
 scf.yield %70 : i64
    }
    %94 = arith.divsi %c1_i64, %89 : i64 //the result should be 0
    vector.print %94 : i64
    return
 }
}
```
However, when I ran different pass sequences on the program, I got inconsistent results of ```0``` and ```Floating point exception```. I tested the sequences respectively, and I found that the inconsistency was caused in the last scf.if operation, which reached the false branch when --int-range-optimizations pass was specified, and reached the true branch when --int-range-optimizations pass was not specified.
I guess there might be a problem in the usage of pass the --int-range-optimizations, when I ran ```mlir-opt --convert-scf-to-cf --convert-cf-to-llvm --int-range-optimizations test.mlir``` on the program, I got the following result:
```
module {
  func.func @func1() {
    %c3_i64 = arith.constant 3 : i64
    %false = arith.constant false
 %c2060639849_i64 = arith.constant 2060639849 : i64
    %c1_i64 = arith.constant 1 : i64
    llvm.cond_br %false, ^bb1(%c1_i64 : i64), ^bb1(%c2060639849_i64 : i64)
  ^bb1(%0: i64):  // 2 preds: ^bb0, ^bb0
 llvm.br ^bb2(%0 : i64)
  ^bb2(%1: i64):  // pred: ^bb1
    llvm.br ^bb3
  ^bb3:  // pred: ^bb2
    %2 = arith.divsi %c1_i64, %1 : i64
 %3 = arith.addi %2, %c2060639849_i64 : i64
    %4 = arith.xori %3, %c2060639849_i64 : i64
    llvm.cond_br %false, ^bb4(%c3_i64 : i64), ^bb4(%4 : i64)
  ^bb4(%5: i64):  // 2 preds: ^bb3, ^bb3
    llvm.br ^bb5(%5 : i64)
  ^bb5(%6: i64):  // pred: ^bb4
    llvm.br ^bb6
 ^bb6:  // pred: ^bb5
    %7 = arith.divsi %c1_i64, %6 : i64
 vector.print %7 : i64
    return
  }
}
```
I've tried to analyze the result manually, and I guess the operation ```llvm.cond_br %false, ^bb4(%c3_i64 : i64), ^bb4(%4 : i64)``` in the result seems to be wrong. The passes seem to turn the operation ```%88 = arith.cmpi eq, %70, %c0_i64 : i64``` into a constant ```false``` value, but in my analysis, the result of this operation is expected to be ```true```.  I'm not sure if there is any bug in my program or some other problems that caused this result.
My git version is 1a8c6130f60fe517fb722ab4309997ce7b638234.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WEtv27oS_jXyZmCDIvXywou0aXAN3G4u7r6gpJHEQiJdknLq_voD6m3HStyec4AgtsiZ-b55eGZsbowoJeLBCz954fOGt7ZS-vDKZXlRsvzu802q8svhCBU_I9gKoVB1rV6FLOHrf4__g5NWpeaNx5488uyRJ4vG7ppa6OnEi8jw1z02Km9rBC_-1D8DFK3Mdu4feAFxr75HE4_uFzIeDQteGwSPPQPXwla7TEljubTQXYy2wIlmlEQkYvsk2H8TUXBPaZYAjz2BiIKB7JUdf03dv9Ya5cmaPHkHhUWdhsmKnShmT7ce-wIeTZxSHwsn_eLRF5cFjaatLZhKtX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