<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111589>111589</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Invalid scf -> cf lowering when the `scf.index_switch` case values are greater than `i32`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kuree
</td>
</tr>
</table>
<pre>
Input:
```mlir
func.func @foo(%arg: index) {
scf.index_switch %arg
case 4294967296 { // 2^32
"op.op"() : () -> ()
scf.yield
}
case 8589934592 { // 2^33
"op.op"() : () -> ()
scf.yield
}
default {
"op.op"() : () -> ()
scf.yield
}
return
}
```
Using latest `mlir-opt`
```mlir
// mlir-opt --convert-scf-to-cf --allow-unregistered-dialect
module {
func.func @foo(%arg0: index) {
%0 = arith.index_cast %arg0 : index to i32
cf.switch %0 : i32, [
default: ^bb3,
0: ^bb1,
0: ^bb2
]
^bb1: // pred: ^bb0
"op.op"() : () -> ()
cf.br ^bb4
^bb2: // pred: ^bb0
"op.op"() : () -> ()
cf.br ^bb4
^bb3: // pred: ^bb0
"op.op"() : () -> ()
cf.br ^bb4
^bb4: // 3 preds: ^bb1, ^bb2, ^bb3
return
}
}
```
This is caused by an overflow here: https://github.com/llvm/llvm-project/blob/3c6041d28c6c185c9d7bc1de6d93148e383b58ed/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp#L672, where the case values are actually `int64_t`.
Link to Goldbolt: https://godbolt.org/z/bvbW51WM4
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VV9vpDYQ_zTeFwtkxsDCAw-5JFRRcy_tVfd4MvawuHXwyja7TT99ZWA3JGkqndSetPIaz4x_M7_5Y-G9PoyIDSk-keJuJ6YwWNf8PDnEXWfVc_MwHqdA-A1hd4TdkJItvyej3XLUT6NM40JJznprCVQECuEOhN9QPSr8k0BNyf7T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