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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][arith] `arith.floordivsi -(2^n -1), -1` generates code that crashes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          pingshiyu
      </td>
    </tr>
</table>

<pre>
    The code below tries to calculate: `arith.floordivsi (1 - 2^63), -1`, which should give a well defined result equalling `2^63 - 1` (as far as I can tell from the documentation). But instead generates code that crashes when compiled with:

`mlir-opt --arith-expand --test-lower-to-llvm out.mlir | mlir-cpu-runner -e main --shared-libs ~/lib/mlir_c_runner --entry-point-result void`

```mlir
"builtin.module"() ({
 ^bb0(): 
        "func.func"() ({
            ^bb0(): 
 "func.call"() {callee=@func0} : () -> ()
 "func.return"() : () -> ()
            }) {sym_name="main", function_type=() -> ()} : () -> ()
        "func.func"() ({
 ^bb0(): 
                %nMaxInt, %n1 = "func.call"() {callee=@func1} : () -> (i64, i64)
                vector.print %nMaxInt : i64 // -(2^n - 1)
                vector.print %n1 : i64      // -1

 %BUG = "arith.floordivsi"(%nMaxInt, %n1) : (i64, i64) -> (i64) 
 vector.print %BUG : i64 // // should == 2^n - 1, but crashes here
 "func.return"() : () -> ()
            }) {sym_name="func0", function_type=() -> ()} : () -> ()
 "func.func"() ({
            ^bb0(): 
                %nMaxInt = arith.constant -9223372036854775807 : i64
                %n1 = arith.constant -1 : i64
                "func.return"(%nMaxInt, %n1) : (i64, i64) -> ()
            }) {sym_name="func1", function_type=() -> (i64, i64)} : () -> ()
    }) : () -> ()
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk1v4zgP_jXKhVAg01_xIYdJ07yYw3vbPReyzcRayFJWH8n0sr99ITuZpp22kwFmhcByZPIR-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