<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98535>98535</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] `scf.index_switch` fold does not converge
</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
// RUN: mlir-opt --allow-unregistered-dialect --canonicalize %s
module {
func.func private @foo(%arg0: !llvm.ptr) -> i32 {
%c1_i32 = arith.constant 1 : i32
%c0_i32 = arith.constant 0 : i32
%c1_i8 = arith.constant 1 : i8
%c0_i8 = arith.constant 0 : i8
%0 = llvm.load %arg0 {alignment = 4 : i64} : !llvm.ptr -> i16
%1 = arith.index_castui %0 : i16 to index
%2 = scf.index_switch %1 -> i32
case 16 {
scf.yield %c1_i32 : i32
}
case 64 {
%3 = arith.index_castui %c1_i32 : i32 to index
scf.index_switch %3
case 0 {
scf.yield
}
default {
"op.op"() : () -> ()
}
scf.yield %c1_i32 : i32
}
default {
%3 = arith.index_castui %c0_i32 : i32 to index
scf.index_switch %3
case 0 {
scf.yield
}
default {
"op.op"() : () -> ()
}
scf.yield %c0_i32 : i32
}
return %2 : i32
}
}
```
See godbolt link that uses trunk: https://godbolt.org/z/f9rrbnojb
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU2P2zYQ_TXUZSCDGn1YPuiwgWsg6MchRc8LihzJTGjSIKlNk19fSNZ6LcVx2gIBDFmk3rx580jMiBB0b4kaVr5j5T4RQzw63_w6eKKkdepL896eh8jyJ8b3jD-xil9-J6P9vIUHhgf48NcfLH-CcT915whpKoxxn9PBeup1iORJpUoLQzICpKkU1lkthdFfCRiW4cJ2cmowBGz77rKGbrByMz7g7PWLiASs4J1zDGuGpfA9H9MyzIx5OW3O0TPcQcryX0DneMMDMGaR2fO0ne9BeB2PG-lsiMJGyGDk0Tku8fx7eH4fnz3r-gF9_Q37XTS_h-YTcirTOKFgLn-sURjd2xPZOEGKS3RVsO0eVu7M1mTVgjq7EaGtor-fpQhx0K9pn8YIiA6mj4vQizlBdnNg-KyjPF5I347hGiFFIMiq5cHAFP9Fk1GLQ1r7u92viKpiTcSwzB8Us6ReV3Svihxu6aesfJ30Rv9Cy1Wvok4MJn4bxxDdeePODHG60Lv5vOrrLb6836f9n9Z9R82PrOOPrLtK-Y_-_cA4eKD3J7jH_4V7nuLg7evVXyCvuLeX1345L2-efxJB71TrTASj7SeIRxFhCBQg-sF-GrmPMZ7D2HynHjujN873DA9fGR66nfetdR_bRDW52uU7kVCTbZFvcZdXZXJsujzLeFHVbSt21ClBdVsoIpSZqgvZZolukGPBt1mGHLEoNl0ucll3JUleZy1tWcHpJLTZTC3E-T7RIQzU7OoyLxMjWjJhGh-I01BAHAeJb0Z42g59YAU3OsTwRhB1NNPI-f239x9YuQdW8fXdYRWHzhkFylEA6yJIZ1_I95QM3jQrZ3Q8Du1GuhPDw5hm_kvP3n0kGRkeJtGB4eGi-6XBfwIAAP__jjvmfw">