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

    <tr>
        <th>Summary</th>
        <td>
            Inconsistent results when using --arith-unsigned-when-equivalent --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() {
 %c8_i32 = arith.constant 8 : i32
    %c29326_i32 = arith.constant 29326 : i32
    %c2_i32 = arith.constant 2 : i32
    %c1_i32 = arith.constant 1 : i32

    %30 = arith.shrsi %c29326_i32, %c2_i32 : i32 // the result should be 7331, which is 1110010100011 of binary
    %47 = math.ctpop %30 : i32 // the result should be 7
    %57 = arith.shli %47, %c1_i32 : i32 // the result should be 14
    %65 = arith.ceildivsi %57, %c8_i32 : i32 // the result should be 2
    vector.print %65 : i32
    return
 }
}
```
However, when I ran ```mlir-opt --arith-expand --arith-unsigned-when-equivalent --int-range-optimizations test.mlir``` on the program, I got the following result:
```
module {
  func.func @func1() {
    %c-536870910_i32 = arith.constant -536870910 : i32
 vector.print %c-536870910_i32 : i32
    return
  }
}
```
And when I ran ```mlir-opt --arith-expand --int-range-optimizations test.mlir``` on the program, I got the following result:
```
 module {
 func.func @func1() {
    %c1_i32 = arith.constant 1 : i32
 vector.print %c1_i32 : i32
    return
  }
}
```
I've tried to analyze my program manually, and my result is that the value of the constant operation seems to be 2, which is different from either of the above results. I'm not sure if there is any bug in my program or some other problems that caused these results.
My git version is 1a8c6130f60fe517fb722ab4309997ce7b638234.

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