<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64231>64231</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SimplifyCFG] `SwitchToLookupTable` missing optimizations.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
DianQK
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DianQK
</td>
</tr>
</table>
<pre>
https://alive2.llvm.org/ce/z/7Mhqtr
```llvm
define i64 @src(i8 %0) {
start:
switch i8 %0, label %bb2 [
i8 126, label %bb3
i8 127, label %bb4
i8 -128, label %bb5
]
bb2:
unreachable
bb3:
br label %bb10
bb4:
br label %bb10
bb5:
br label %bb10
bb10:
%result= phi i64 [ 3, %bb3 ], [ 4, %bb4 ], [ 5, %bb5 ]
ret i64 %result
}
```
It can be converted to:
```llvm
define i64 @tgt(i8 %0) {
start:
%switch.tableidx = sub i8 %0, 126
%switch.idx.cast = zext i8 %switch.tableidx to i64
%switch.offset = add nuw nsw i64 %switch.idx.cast, 3
ret i64 %switch.offset
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN2OmzoQfprhxgoyY2zCBRebRRwdndOLavcFbHCCW4JTbPbv6StDliW0VVeKgjzzzd_nzyOdM6de6wL4ARBLI_uv_wEi8DKSo2_tUMy2SNnmtWi9vzhgd4AVYCU786Qx7rqnc2yHE2BVa8DqDbDKvrQ__AC0BHoHgs6_AJxNjT6aXhMjUgIpdUMNuDd7AsgpYE4gO8w45-XgQ73pRIh7Nr5uyQK9J51UugsnpZCEIa5IEkAJig2GbfzZxp_e-HcJ7jcAfgUAL6_TTf9K4arNsR-0rFupOn0LYiuQGtZ5E3qLTD-N5J9GJnQFBeSDdmPngZXk0pr5MviBsDDxTNY0ZTjxA0kXc7o288XMPzghZNB-TrhUmTvJyo0m5uO_ntSyJ0qT2vZPevC6Id4u3f5VQf7kP6kgQD6LKPbhekzzQgIBblRrVQXh_BJgmpe4ls5PAW_6xV8jtvm8DW2962Tx2-PR6TlYNg3px2fSu-d3ljY1QhPsN2Te5PoTp1FTsCZnuYx0kYicZglmSKO20LXSWS2lyPKcoeD7XAjKKK2ZboTQIjIFUmQ0YzShyJHGCRfHvdLqyCTdK1lDSvVZmm559JFxbtSFSJEl0aQ9d90l012xO3vx5mzepDe2d2Gz4D0gno1zutmtndetMxQhcKfGk4OUdsZ591HMG99Nu-rBnC-dOb7eV_8ALwkI-jAx82j_t_b7eHmc3p6gJBQy_YnctBFH49BtltnJ-HZUcW3PgNXU-_zZXQb7TdcesJpGdYDVNO3PAAAA___CB3aH">